@@ -56,21 +56,22 @@ pub enum TreatParams {
5656 AsCandidateKey ,
5757 /// Treat parameters as placeholders in the given environment. This is the
5858 /// correct mode for *lookup*, as during candidate selection.
59+ ///
60+ /// This also treats projections with inference variables as infer vars
61+ /// since they could be further normalized.
5962 ForLookup ,
63+ /// Treat parameters as placeholders in the given environment. This is the
64+ /// correct mode for *lookup*, as during candidate selection.
65+ ///
66+ /// N.B. during deep rejection, this acts identically to `ForLookup`.
67+ NextSolverLookup ,
6068}
6169
6270/// During fast-rejection, we have the choice of treating projection types
6371/// as either simplifyable or not, depending on whether we expect the projection
6472/// to be normalized/rigid.
6573#[ derive( PartialEq , Eq , Debug , Clone , Copy ) ]
6674pub enum TreatProjections {
67- /// In candidates, we may be able to normalize the projection
68- /// after instantiating the candidate and equating it with a goal.
69- ///
70- /// We must assume that the `impl<T> Trait<T> for <T as Id>::This`
71- /// can apply to all self types so we don't return a simplified type
72- /// for `<T as Id>::This`.
73- AsCandidateKey ,
7475 /// In the old solver we don't try to normalize projections
7576 /// when looking up impls and only access them by using the
7677 /// current self type. This means that if the self type is
@@ -107,7 +108,6 @@ pub fn simplify_type<'tcx>(
107108 tcx : TyCtxt < ' tcx > ,
108109 ty : Ty < ' tcx > ,
109110 treat_params : TreatParams ,
110- treat_projections : TreatProjections ,
111111) -> Option < SimplifiedType > {
112112 match * ty. kind ( ) {
113113 ty:: Bool => Some ( BoolSimplifiedType ) ,
@@ -136,13 +136,20 @@ pub fn simplify_type<'tcx>(
136136 ty:: FnPtr ( f) => Some ( FunctionSimplifiedType ( f. skip_binder ( ) . inputs ( ) . len ( ) ) ) ,
137137 ty:: Placeholder ( ..) => Some ( PlaceholderSimplifiedType ) ,
138138 ty:: Param ( _) => match treat_params {
139- TreatParams :: ForLookup => Some ( PlaceholderSimplifiedType ) ,
139+ TreatParams :: ForLookup | TreatParams :: NextSolverLookup => {
140+ Some ( PlaceholderSimplifiedType )
141+ }
140142 TreatParams :: AsCandidateKey => None ,
141143 } ,
142- ty:: Alias ( ..) => match treat_projections {
143- TreatProjections :: ForLookup if !ty. needs_infer ( ) => Some ( PlaceholderSimplifiedType ) ,
144- TreatProjections :: NextSolverLookup => Some ( PlaceholderSimplifiedType ) ,
145- TreatProjections :: AsCandidateKey | TreatProjections :: ForLookup => None ,
144+ ty:: Alias ( ..) => match treat_params {
145+ // When treating `ty::Param` as a placeholder, projections also
146+ // don't unify with anything else as long as they are fully normalized.
147+ //
148+ // We will have to be careful with lazy normalization here.
149+ // FIXME(lazy_normalization): This is probably not right...
150+ TreatParams :: ForLookup if !ty. has_non_region_infer ( ) => Some ( PlaceholderSimplifiedType ) ,
151+ TreatParams :: NextSolverLookup => Some ( PlaceholderSimplifiedType ) ,
152+ TreatParams :: ForLookup | TreatParams :: AsCandidateKey => None ,
146153 } ,
147154 ty:: Foreign ( def_id) => Some ( ForeignSimplifiedType ( def_id) ) ,
148155 ty:: Bound ( ..) | ty:: Infer ( _) | ty:: Error ( _) => None ,
@@ -310,7 +317,7 @@ impl DeepRejectCtxt {
310317 // Depending on the value of `treat_obligation_params`, we either
311318 // treat generic parameters like placeholders or like inference variables.
312319 ty:: Param ( _) => match self . treat_obligation_params {
313- TreatParams :: ForLookup => false ,
320+ TreatParams :: ForLookup | TreatParams :: NextSolverLookup => false ,
314321 TreatParams :: AsCandidateKey => true ,
315322 } ,
316323
@@ -348,7 +355,7 @@ impl DeepRejectCtxt {
348355 let k = impl_ct. kind ( ) ;
349356 match obligation_ct. kind ( ) {
350357 ty:: ConstKind :: Param ( _) => match self . treat_obligation_params {
351- TreatParams :: ForLookup => false ,
358+ TreatParams :: ForLookup | TreatParams :: NextSolverLookup => false ,
352359 TreatParams :: AsCandidateKey => true ,
353360 } ,
354361
0 commit comments