@@ -8,10 +8,9 @@ use std::fmt;
88use hir_def:: { TraitId , TypeAliasId } ;
99use rustc_type_ir:: inherent:: { IntoKind , Ty as _} ;
1010use tracing:: debug;
11- use triomphe:: Arc ;
1211
1312use crate :: {
14- TraitEnvironment ,
13+ ParamEnvAndCrate ,
1514 db:: HirDatabase ,
1615 infer:: InferenceContext ,
1716 next_solver:: {
@@ -35,13 +34,13 @@ const AUTODEREF_RECURSION_LIMIT: usize = 20;
3534/// detects a cycle in the deref chain.
3635pub fn autoderef < ' db > (
3736 db : & ' db dyn HirDatabase ,
38- env : Arc < TraitEnvironment < ' db > > ,
37+ env : ParamEnvAndCrate < ' db > ,
3938 ty : Canonical < ' db , Ty < ' db > > ,
4039) -> impl Iterator < Item = Ty < ' db > > + use < ' db > {
4140 let interner = DbInterner :: new_with ( db, env. krate ) ;
4241 let infcx = interner. infer_ctxt ( ) . build ( TypingMode :: PostAnalysis ) ;
4342 let ( ty, _) = infcx. instantiate_canonical ( & ty) ;
44- let autoderef = Autoderef :: new ( & infcx, & env, ty) ;
43+ let autoderef = Autoderef :: new ( & infcx, env. param_env , ty) ;
4544 let mut v = Vec :: new ( ) ;
4645 for ( ty, _steps) in autoderef {
4746 // `ty` may contain unresolved inference variables. Since there's no chance they would be
@@ -111,21 +110,21 @@ struct AutoderefTraits {
111110// borrows it.
112111pub ( crate ) trait AutoderefCtx < ' db > {
113112 fn infcx ( & self ) -> & InferCtxt < ' db > ;
114- fn env ( & self ) -> & TraitEnvironment < ' db > ;
113+ fn param_env ( & self ) -> ParamEnv < ' db > ;
115114}
116115
117116pub ( crate ) struct DefaultAutoderefCtx < ' a , ' db > {
118117 infcx : & ' a InferCtxt < ' db > ,
119- env : & ' a TraitEnvironment < ' db > ,
118+ param_env : ParamEnv < ' db > ,
120119}
121120impl < ' db > AutoderefCtx < ' db > for DefaultAutoderefCtx < ' _ , ' db > {
122121 #[ inline]
123122 fn infcx ( & self ) -> & InferCtxt < ' db > {
124123 self . infcx
125124 }
126125 #[ inline]
127- fn env ( & self ) -> & TraitEnvironment < ' db > {
128- self . env
126+ fn param_env ( & self ) -> ParamEnv < ' db > {
127+ self . param_env
129128 }
130129}
131130
@@ -136,8 +135,8 @@ impl<'db> AutoderefCtx<'db> for InferenceContextAutoderefCtx<'_, '_, 'db> {
136135 & self . 0 . table . infer_ctxt
137136 }
138137 #[ inline]
139- fn env ( & self ) -> & TraitEnvironment < ' db > {
140- & self . 0 . table . trait_env
138+ fn param_env ( & self ) -> ParamEnv < ' db > {
139+ self . 0 . table . param_env
141140 }
142141}
143142
@@ -201,7 +200,7 @@ where
201200 // autoderef expect this type to have been structurally normalized.
202201 if let TyKind :: Alias ( ..) = ty. kind ( ) {
203202 let ( normalized_ty, obligations) =
204- structurally_normalize_ty ( self . infcx ( ) , self . env ( ) . env , ty) ?;
203+ structurally_normalize_ty ( self . infcx ( ) , self . param_env ( ) , ty) ?;
205204 self . state . obligations . extend ( obligations) ;
206205 ( AutoderefKind :: Builtin , normalized_ty)
207206 } else {
@@ -231,10 +230,10 @@ impl<'a, 'db> Autoderef<'a, 'db> {
231230 #[ inline]
232231 pub ( crate ) fn new_with_tracking (
233232 infcx : & ' a InferCtxt < ' db > ,
234- env : & ' a TraitEnvironment < ' db > ,
233+ param_env : ParamEnv < ' db > ,
235234 base_ty : Ty < ' db > ,
236235 ) -> Self {
237- Self :: new_impl ( DefaultAutoderefCtx { infcx, env } , base_ty)
236+ Self :: new_impl ( DefaultAutoderefCtx { infcx, param_env } , base_ty)
238237 }
239238}
240239
@@ -257,10 +256,10 @@ impl<'a, 'db> Autoderef<'a, 'db, usize> {
257256 #[ inline]
258257 pub ( crate ) fn new (
259258 infcx : & ' a InferCtxt < ' db > ,
260- env : & ' a TraitEnvironment < ' db > ,
259+ param_env : ParamEnv < ' db > ,
261260 base_ty : Ty < ' db > ,
262261 ) -> Self {
263- Self :: new_impl ( DefaultAutoderefCtx { infcx, env } , base_ty)
262+ Self :: new_impl ( DefaultAutoderefCtx { infcx, param_env } , base_ty)
264263 }
265264}
266265
@@ -292,8 +291,8 @@ where
292291 }
293292
294293 #[ inline]
295- fn env ( & self ) -> & TraitEnvironment < ' db > {
296- self . ctx . env ( )
294+ fn param_env ( & self ) -> ParamEnv < ' db > {
295+ self . ctx . param_env ( )
297296 }
298297
299298 #[ inline]
@@ -339,7 +338,7 @@ where
339338
340339 let trait_ref = TraitRef :: new ( interner, trait_. into ( ) , [ ty] ) ;
341340 let obligation =
342- Obligation :: new ( interner, ObligationCause :: new ( ) , self . env ( ) . env , trait_ref) ;
341+ Obligation :: new ( interner, ObligationCause :: new ( ) , self . param_env ( ) , trait_ref) ;
343342 // We detect whether the self type implements `Deref` before trying to
344343 // structurally normalize. We use `predicate_may_hold_opaque_types_jank`
345344 // to support not-yet-defined opaque types. It will succeed for `impl Deref`
@@ -351,7 +350,7 @@ where
351350
352351 let ( normalized_ty, obligations) = structurally_normalize_ty (
353352 self . infcx ( ) ,
354- self . env ( ) . env ,
353+ self . param_env ( ) ,
355354 Ty :: new_projection ( interner, trait_target. into ( ) , [ ty] ) ,
356355 ) ?;
357356 debug ! ( "overloaded_deref_ty({:?}) = ({:?}, {:?})" , ty, normalized_ty, obligations) ;
0 commit comments