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