@@ -14,10 +14,8 @@ use rustc_infer::traits::util;
14
14
use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
15
15
use rustc_middle:: ty:: util:: ExplicitSelf ;
16
16
use rustc_middle:: ty:: {
17
- self , AssocItem , DefIdTree , TraitRef , Ty , TypeFoldable , TypeFolder , TypeSuperFoldable ,
18
- TypeVisitable ,
17
+ self , DefIdTree , InternalSubsts , Ty , TypeFoldable , TypeFolder , TypeSuperFoldable , TypeVisitable ,
19
18
} ;
20
- use rustc_middle:: ty:: { FnSig , InternalSubsts } ;
21
19
use rustc_middle:: ty:: { GenericParamDefKind , ToPredicate , TyCtxt } ;
22
20
use rustc_span:: Span ;
23
21
use rustc_trait_selection:: traits:: error_reporting:: TypeErrCtxtExt ;
@@ -144,9 +142,9 @@ pub(crate) fn compare_impl_method<'tcx>(
144
142
#[ instrument( level = "debug" , skip( tcx, impl_m_span, impl_trait_ref) ) ]
145
143
fn compare_predicate_entailment < ' tcx > (
146
144
tcx : TyCtxt < ' tcx > ,
147
- impl_m : & AssocItem ,
145
+ impl_m : & ty :: AssocItem ,
148
146
impl_m_span : Span ,
149
- trait_m : & AssocItem ,
147
+ trait_m : & ty :: AssocItem ,
150
148
impl_trait_ref : ty:: TraitRef < ' tcx > ,
151
149
) -> Result < ( ) , ErrorGuaranteed > {
152
150
let trait_to_impl_substs = impl_trait_ref. substs ;
@@ -157,8 +155,7 @@ fn compare_predicate_entailment<'tcx>(
157
155
// FIXME(@lcnr): remove that after removing `cause.body_id` from
158
156
// obligations.
159
157
let impl_m_hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( impl_m. def_id . expect_local ( ) ) ;
160
- // We sometimes modify the span further down.
161
- let mut cause = ObligationCause :: new (
158
+ let cause = ObligationCause :: new (
162
159
impl_m_span,
163
160
impl_m_hir_id,
164
161
ObligationCauseCode :: CompareImplItemObligation {
@@ -307,14 +304,13 @@ fn compare_predicate_entailment<'tcx>(
307
304
debug ! ( ?terr, "sub_types failed: impl ty {:?}, trait ty {:?}" , impl_fty, trait_fty) ;
308
305
309
306
let emitted = report_trait_method_mismatch (
310
- tcx,
311
- & mut cause,
312
307
& infcx,
308
+ cause,
313
309
terr,
314
310
( trait_m, trait_fty) ,
315
311
( impl_m, impl_fty) ,
316
- & trait_sig,
317
- & impl_trait_ref,
312
+ trait_sig,
313
+ impl_trait_ref,
318
314
) ;
319
315
return Err ( emitted) ;
320
316
}
@@ -360,7 +356,7 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
360
356
361
357
let impl_m_hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( impl_m. def_id . expect_local ( ) ) ;
362
358
let return_span = tcx. hir ( ) . fn_decl_by_hir_id ( impl_m_hir_id) . unwrap ( ) . output . span ( ) ;
363
- let mut cause = ObligationCause :: new (
359
+ let cause = ObligationCause :: new (
364
360
return_span,
365
361
impl_m_hir_id,
366
362
ObligationCauseCode :: CompareImplItemObligation {
@@ -457,14 +453,13 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
457
453
// emit an error now because `compare_predicate_entailment` will not report the error
458
454
// when normalization fails.
459
455
let emitted = report_trait_method_mismatch (
460
- tcx,
461
- & mut cause,
462
456
infcx,
457
+ cause,
463
458
terr,
464
459
( trait_m, trait_fty) ,
465
460
( impl_m, impl_fty) ,
466
- & trait_sig,
467
- & impl_trait_ref,
461
+ trait_sig,
462
+ impl_trait_ref,
468
463
) ;
469
464
return Err ( emitted) ;
470
465
}
@@ -634,23 +629,21 @@ impl<'tcx> TypeFolder<'tcx> for ImplTraitInTraitCollector<'_, 'tcx> {
634
629
}
635
630
636
631
fn report_trait_method_mismatch < ' tcx > (
637
- tcx : TyCtxt < ' tcx > ,
638
- cause : & mut ObligationCause < ' tcx > ,
639
632
infcx : & InferCtxt < ' tcx > ,
633
+ mut cause : ObligationCause < ' tcx > ,
640
634
terr : TypeError < ' tcx > ,
641
- ( trait_m, trait_fty) : ( & AssocItem , Ty < ' tcx > ) ,
642
- ( impl_m, impl_fty) : ( & AssocItem , Ty < ' tcx > ) ,
643
- trait_sig : & FnSig < ' tcx > ,
644
- impl_trait_ref : & TraitRef < ' tcx > ,
635
+ ( trait_m, trait_fty) : ( & ty :: AssocItem , Ty < ' tcx > ) ,
636
+ ( impl_m, impl_fty) : ( & ty :: AssocItem , Ty < ' tcx > ) ,
637
+ trait_sig : ty :: FnSig < ' tcx > ,
638
+ impl_trait_ref : ty :: TraitRef < ' tcx > ,
645
639
) -> ErrorGuaranteed {
640
+ let tcx = infcx. tcx ;
646
641
let ( impl_err_span, trait_err_span) =
647
642
extract_spans_for_error_reporting ( & infcx, terr, & cause, impl_m, trait_m) ;
648
643
649
- cause. span = impl_err_span;
650
-
651
644
let mut diag = struct_span_err ! (
652
645
tcx. sess,
653
- cause . span ( ) ,
646
+ impl_err_span ,
654
647
E0053 ,
655
648
"method `{}` has an incompatible type for trait" ,
656
649
trait_m. name
@@ -721,6 +714,7 @@ fn report_trait_method_mismatch<'tcx>(
721
714
_ => { }
722
715
}
723
716
717
+ cause. span = impl_err_span;
724
718
infcx. err_ctxt ( ) . note_type_err (
725
719
& mut diag,
726
720
& cause,
0 commit comments