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.
114use super :: { EvalCtxt , SolverMode } ;
215use rustc_infer:: traits:: query:: NoSolution ;
316use rustc_middle:: traits:: solve:: { Certainty , Goal , QueryResult } ;
@@ -118,6 +131,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
118131 } )
119132 }
120133
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.
121136 fn normalizes_to_inner (
122137 & mut self ,
123138 param_env : ty:: ParamEnv < ' tcx > ,
@@ -127,9 +142,13 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
127142 invert : Invert ,
128143 ) -> Result < ( ) , NoSolution > {
129144 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.
131147 ty:: AliasRelationDirection :: Equate => other,
132148
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.
133152 ty:: AliasRelationDirection :: Subtype => {
134153 let fresh = self . next_term_infer_of_kind ( other) ;
135154 let ( sub, sup) = match invert {
0 commit comments