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.
113use super :: { EvalCtxt , SolverMode } ;
214use rustc_infer:: traits:: query:: NoSolution ;
315use rustc_middle:: traits:: solve:: { Certainty , Goal , QueryResult } ;
@@ -115,6 +127,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
115127 } )
116128 }
117129
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.
118132 fn normalizes_to_inner (
119133 & mut self ,
120134 param_env : ty:: ParamEnv < ' tcx > ,
@@ -124,9 +138,13 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
124138 invert : Invert ,
125139 ) -> Result < ( ) , NoSolution > {
126140 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.
128143 ty:: AliasRelationDirection :: Equate => other,
129144
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.
130148 ty:: AliasRelationDirection :: Subtype => {
131149 let fresh = self . next_term_infer_of_kind ( other) ;
132150 let ( sub, sup) = match invert {
0 commit comments