1
+ //! Implements the `AliasRelate` goal, which is used to unify two aliases in the
2
+ //! new solver, which uses "lazy normalization".
3
+ //!
4
+ //! This goal, e.g. `A alias-relate B`, may be satisfied by one of three branches:
5
+ //! * normalizes-to: If `A` is a projection, we can prove the equivalent
6
+ //! projection predicate with B as the right-hand side of the projection.
7
+ //! This goal is computed in both directions, if both are aliases.
8
+ //! * subst-relate: Equate `A` and `B` by their substs, if they're both
9
+ //! aliases with the same def-id.
10
+ //! * bidirectional-normalizes-to: If `A` and `B` are both projections, and both
11
+ //! may apply, then we can compute the "intersection" of both normalizes-to by
12
+ //! performing them together. This is used specifically to resolve ambiguities.
1
13
use super :: { EvalCtxt , SolverMode } ;
2
14
use rustc_infer:: traits:: query:: NoSolution ;
3
15
use rustc_middle:: traits:: solve:: { Certainty , Goal , QueryResult } ;
@@ -115,6 +127,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
115
127
} )
116
128
}
117
129
130
+ // Computes the normalizes-to branch, with side-effects. This must be performed
131
+ // in a probe in order to not taint the evaluation context.
118
132
fn normalizes_to_inner (
119
133
& mut self ,
120
134
param_env : ty:: ParamEnv < ' tcx > ,
@@ -124,9 +138,13 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
124
138
invert : Invert ,
125
139
) -> Result < ( ) , NoSolution > {
126
140
let other = match direction {
127
- // This is purely an optimization.
141
+ // This is purely an optimization. No need to instantiate a new
142
+ // infer var and equate the RHS to it.
128
143
ty:: AliasRelationDirection :: Equate => other,
129
144
145
+ // Instantiate an infer var and subtype our RHS to it, so that we
146
+ // properly represent a subtype relation between the LHS and RHS
147
+ // of the goal.
130
148
ty:: AliasRelationDirection :: Subtype => {
131
149
let fresh = self . next_term_infer_of_kind ( other) ;
132
150
let ( sub, sup) = match invert {
0 commit comments