@@ -109,14 +109,14 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
109
109
pub fn new (
110
110
infcx : & ' a InferCtxt < ' tcx > ,
111
111
param_env : ty:: ParamEnv < ' tcx > ,
112
- body_def_id : LocalDefId ,
112
+ body_id : LocalDefId ,
113
113
span : Span ,
114
114
base_ty : Ty < ' tcx > ,
115
115
) -> Autoderef < ' a , ' tcx > {
116
116
Autoderef {
117
117
infcx,
118
118
span,
119
- body_id : body_def_id ,
119
+ body_id,
120
120
param_env,
121
121
state : AutoderefSnapshot {
122
122
steps : vec ! [ ] ,
@@ -135,7 +135,21 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
135
135
let tcx = self . infcx . tcx ;
136
136
137
137
// <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) ;
139
153
let cause = traits:: ObligationCause :: misc ( self . span , self . body_id ) ;
140
154
let obligation = traits:: Obligation :: new (
141
155
tcx,
@@ -151,7 +165,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
151
165
let ( normalized_ty, obligations) = self . structurally_normalize ( Ty :: new_projection (
152
166
tcx,
153
167
tcx. lang_items ( ) . deref_target ( ) ?,
154
- [ ty ] ,
168
+ trait_ref . args ,
155
169
) ) ?;
156
170
debug ! ( "overloaded_deref_ty({:?}) = ({:?}, {:?})" , ty, normalized_ty, obligations) ;
157
171
self . state . obligations . extend ( obligations) ;
0 commit comments