@@ -109,14 +109,14 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
109109 pub fn new (
110110 infcx : & ' a InferCtxt < ' tcx > ,
111111 param_env : ty:: ParamEnv < ' tcx > ,
112- body_def_id : LocalDefId ,
112+ body_id : LocalDefId ,
113113 span : Span ,
114114 base_ty : Ty < ' tcx > ,
115115 ) -> Autoderef < ' a , ' tcx > {
116116 Autoderef {
117117 infcx,
118118 span,
119- body_id : body_def_id ,
119+ body_id,
120120 param_env,
121121 state : AutoderefSnapshot {
122122 steps : vec ! [ ] ,
@@ -135,7 +135,21 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
135135 let tcx = self . infcx . tcx ;
136136
137137 // <ty as Deref>
138- let trait_ref = ty:: TraitRef :: new ( tcx, tcx. lang_items ( ) . deref_trait ( ) ?, [ ty] ) ;
138+ let deref_trait_def_id = tcx. lang_items ( ) . deref_trait ( ) ?;
139+
140+ // FIXME(effects): This is still broken, since we don't necessarily have a choice of
141+ // `host = true` or `host = host` in `const` functions. This is also busted in `method_autoderef_steps`.
142+ let deref_generics = self . infcx . tcx . generics_of ( deref_trait_def_id) ;
143+ let args = if let Some ( host_param) = deref_generics. host_effect_index {
144+ self . infcx . tcx . mk_args ( & [
145+ ty. into ( ) ,
146+ self . infcx . var_for_def ( self . span , & deref_generics. params [ host_param] ) ,
147+ ] )
148+ } else {
149+ self . infcx . tcx . mk_args ( & [ ty. into ( ) ] )
150+ } ;
151+
152+ let trait_ref = ty:: TraitRef :: new ( tcx, deref_trait_def_id, args) ;
139153 let cause = traits:: ObligationCause :: misc ( self . span , self . body_id ) ;
140154 let obligation = traits:: Obligation :: new (
141155 tcx,
@@ -151,7 +165,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
151165 let ( normalized_ty, obligations) = self . structurally_normalize ( Ty :: new_projection (
152166 tcx,
153167 tcx. lang_items ( ) . deref_target ( ) ?,
154- [ ty ] ,
168+ trait_ref . args ,
155169 ) ) ?;
156170 debug ! ( "overloaded_deref_ty({:?}) = ({:?}, {:?})" , ty, normalized_ty, obligations) ;
157171 self . state . obligations . extend ( obligations) ;
0 commit comments