@@ -40,7 +40,7 @@ pub fn autoderef<'db>(
4040 let interner = DbInterner :: new_with ( db, env. krate ) ;
4141 let infcx = interner. infer_ctxt ( ) . build ( TypingMode :: PostAnalysis ) ;
4242 let ( ty, _) = infcx. instantiate_canonical ( Span :: Dummy , & ty) ;
43- let autoderef = Autoderef :: new ( & infcx, env. param_env , ty) ;
43+ let autoderef = Autoderef :: new ( & infcx, env. param_env , ty, Span :: Dummy ) ;
4444 let mut v = Vec :: new ( ) ;
4545 for ( ty, _steps) in autoderef {
4646 // `ty` may contain unresolved inference variables. Since there's no chance they would be
@@ -155,6 +155,7 @@ pub(crate) struct GeneralAutoderef<'db, Ctx, Steps = Vec<(Ty<'db>, AutoderefKind
155155 // Configurations:
156156 include_raw_pointers : bool ,
157157 use_receiver_trait : bool ,
158+ span : Span ,
158159}
159160
160161pub ( crate ) type Autoderef < ' a , ' db , Steps = Vec < ( Ty < ' db > , AutoderefKind ) > > =
@@ -200,7 +201,7 @@ where
200201 // autoderef expect this type to have been structurally normalized.
201202 if let TyKind :: Alias ( ..) = ty. kind ( ) {
202203 let ( normalized_ty, obligations) =
203- structurally_normalize_ty ( self . infcx ( ) , self . param_env ( ) , ty) ?;
204+ structurally_normalize_ty ( self . infcx ( ) , self . param_env ( ) , ty, self . span ) ?;
204205 self . state . obligations . extend ( obligations) ;
205206 ( AutoderefKind :: Builtin , normalized_ty)
206207 } else {
@@ -232,8 +233,9 @@ impl<'a, 'db> Autoderef<'a, 'db> {
232233 infcx : & ' a InferCtxt < ' db > ,
233234 param_env : ParamEnv < ' db > ,
234235 base_ty : Ty < ' db > ,
236+ span : Span ,
235237 ) -> Self {
236- Self :: new_impl ( DefaultAutoderefCtx { infcx, param_env } , base_ty)
238+ Self :: new_impl ( DefaultAutoderefCtx { infcx, param_env } , base_ty, span )
237239 }
238240}
239241
@@ -242,8 +244,9 @@ impl<'a, 'b, 'db> InferenceContextAutoderef<'a, 'b, 'db> {
242244 pub ( crate ) fn new_from_inference_context (
243245 ctx : & ' a mut InferenceContext < ' b , ' db > ,
244246 base_ty : Ty < ' db > ,
247+ span : Span ,
245248 ) -> Self {
246- Self :: new_impl ( InferenceContextAutoderefCtx ( ctx) , base_ty)
249+ Self :: new_impl ( InferenceContextAutoderefCtx ( ctx) , base_ty, span )
247250 }
248251
249252 #[ inline]
@@ -258,8 +261,9 @@ impl<'a, 'db> Autoderef<'a, 'db, usize> {
258261 infcx : & ' a InferCtxt < ' db > ,
259262 param_env : ParamEnv < ' db > ,
260263 base_ty : Ty < ' db > ,
264+ span : Span ,
261265 ) -> Self {
262- Self :: new_impl ( DefaultAutoderefCtx { infcx, param_env } , base_ty)
266+ Self :: new_impl ( DefaultAutoderefCtx { infcx, param_env } , base_ty, span )
263267 }
264268}
265269
@@ -269,7 +273,7 @@ where
269273 Steps : TrackAutoderefSteps < ' db > ,
270274{
271275 #[ inline]
272- fn new_impl ( ctx : Ctx , base_ty : Ty < ' db > ) -> Self {
276+ fn new_impl ( ctx : Ctx , base_ty : Ty < ' db > , span : Span ) -> Self {
273277 GeneralAutoderef {
274278 state : AutoderefSnapshot {
275279 steps : Steps :: default ( ) ,
@@ -282,6 +286,7 @@ where
282286 traits : None ,
283287 include_raw_pointers : false ,
284288 use_receiver_trait : false ,
289+ span,
285290 }
286291 }
287292
@@ -338,7 +343,7 @@ where
338343
339344 let trait_ref = TraitRef :: new ( interner, trait_. into ( ) , [ ty] ) ;
340345 let obligation =
341- Obligation :: new ( interner, ObligationCause :: new ( ) , self . param_env ( ) , trait_ref) ;
346+ Obligation :: new ( interner, ObligationCause :: new ( self . span ) , self . param_env ( ) , trait_ref) ;
342347 // We detect whether the self type implements `Deref` before trying to
343348 // structurally normalize. We use `predicate_may_hold_opaque_types_jank`
344349 // to support not-yet-defined opaque types. It will succeed for `impl Deref`
@@ -352,6 +357,7 @@ where
352357 self . infcx ( ) ,
353358 self . param_env ( ) ,
354359 Ty :: new_projection ( interner, trait_target. into ( ) , [ ty] ) ,
360+ self . span ,
355361 ) ?;
356362 debug ! ( "overloaded_deref_ty({:?}) = ({:?}, {:?})" , ty, normalized_ty, obligations) ;
357363 self . state . obligations . extend ( obligations) ;
@@ -403,9 +409,11 @@ fn structurally_normalize_ty<'db>(
403409 infcx : & InferCtxt < ' db > ,
404410 param_env : ParamEnv < ' db > ,
405411 ty : Ty < ' db > ,
412+ span : Span ,
406413) -> Option < ( Ty < ' db > , PredicateObligations < ' db > ) > {
407414 let mut ocx = ObligationCtxt :: new ( infcx) ;
408- let Ok ( normalized_ty) = ocx. structurally_normalize_ty ( & ObligationCause :: misc ( ) , param_env, ty)
415+ let Ok ( normalized_ty) =
416+ ocx. structurally_normalize_ty ( & ObligationCause :: new ( span) , param_env, ty)
409417 else {
410418 // We shouldn't have errors here in the old solver, except for
411419 // evaluate/fulfill mismatches, but that's not a reason for an ICE.
0 commit comments