@@ -56,21 +56,22 @@ pub enum TreatParams {
56
56
AsCandidateKey ,
57
57
/// Treat parameters as placeholders in the given environment. This is the
58
58
/// 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.
59
62
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 ,
60
68
}
61
69
62
70
/// During fast-rejection, we have the choice of treating projection types
63
71
/// as either simplifyable or not, depending on whether we expect the projection
64
72
/// to be normalized/rigid.
65
73
#[ derive( PartialEq , Eq , Debug , Clone , Copy ) ]
66
74
pub 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 ,
74
75
/// In the old solver we don't try to normalize projections
75
76
/// when looking up impls and only access them by using the
76
77
/// current self type. This means that if the self type is
@@ -107,7 +108,6 @@ pub fn simplify_type<'tcx>(
107
108
tcx : TyCtxt < ' tcx > ,
108
109
ty : Ty < ' tcx > ,
109
110
treat_params : TreatParams ,
110
- treat_projections : TreatProjections ,
111
111
) -> Option < SimplifiedType > {
112
112
match * ty. kind ( ) {
113
113
ty:: Bool => Some ( BoolSimplifiedType ) ,
@@ -136,13 +136,20 @@ pub fn simplify_type<'tcx>(
136
136
ty:: FnPtr ( f) => Some ( FunctionSimplifiedType ( f. skip_binder ( ) . inputs ( ) . len ( ) ) ) ,
137
137
ty:: Placeholder ( ..) => Some ( PlaceholderSimplifiedType ) ,
138
138
ty:: Param ( _) => match treat_params {
139
- TreatParams :: ForLookup => Some ( PlaceholderSimplifiedType ) ,
139
+ TreatParams :: ForLookup | TreatParams :: NextSolverLookup => {
140
+ Some ( PlaceholderSimplifiedType )
141
+ }
140
142
TreatParams :: AsCandidateKey => None ,
141
143
} ,
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 ,
146
153
} ,
147
154
ty:: Foreign ( def_id) => Some ( ForeignSimplifiedType ( def_id) ) ,
148
155
ty:: Bound ( ..) | ty:: Infer ( _) | ty:: Error ( _) => None ,
@@ -310,7 +317,7 @@ impl DeepRejectCtxt {
310
317
// Depending on the value of `treat_obligation_params`, we either
311
318
// treat generic parameters like placeholders or like inference variables.
312
319
ty:: Param ( _) => match self . treat_obligation_params {
313
- TreatParams :: ForLookup => false ,
320
+ TreatParams :: ForLookup | TreatParams :: NextSolverLookup => false ,
314
321
TreatParams :: AsCandidateKey => true ,
315
322
} ,
316
323
@@ -348,7 +355,7 @@ impl DeepRejectCtxt {
348
355
let k = impl_ct. kind ( ) ;
349
356
match obligation_ct. kind ( ) {
350
357
ty:: ConstKind :: Param ( _) => match self . treat_obligation_params {
351
- TreatParams :: ForLookup => false ,
358
+ TreatParams :: ForLookup | TreatParams :: NextSolverLookup => false ,
352
359
TreatParams :: AsCandidateKey => true ,
353
360
} ,
354
361
0 commit comments