@@ -205,7 +205,6 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinte
205
205
}
206
206
} ;
207
207
printer. ty_infer_name_resolver = Some ( Box :: new ( ty_getter) ) ;
208
- printer. for_suggestion = true ;
209
208
let const_getter =
210
209
move |ct_vid| Some ( infcx. tcx . item_name ( infcx. const_var_origin ( ct_vid) ?. param_def_id ?) ) ;
211
210
printer. const_infer_name_resolver = Some ( Box :: new ( const_getter) ) ;
@@ -419,6 +418,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
419
418
arg : GenericArg < ' tcx > ,
420
419
error_code : TypeAnnotationNeeded ,
421
420
should_label_span : bool ,
421
+ param_env : ty:: ParamEnv < ' tcx > ,
422
422
) -> Diag < ' a > {
423
423
let arg = self . resolve_vars_if_possible ( arg) ;
424
424
let arg_data = self . extract_inference_diagnostics_data ( arg, None ) ;
@@ -454,7 +454,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
454
454
match kind {
455
455
InferSourceKind :: LetBinding { insert_span, pattern_name, ty, def_id, hir_id } => {
456
456
let mut paths = vec ! [ ] ;
457
- let param_env = ty:: ParamEnv :: reveal_all ( ) ;
458
457
if let Some ( def_id) = def_id
459
458
&& let name = self . infcx . tcx . item_name ( def_id)
460
459
&& let Some ( hir_id) = hir_id
@@ -468,7 +467,25 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
468
467
self . infcx . tcx . parent ( def_id) , // Trait `DefId`
469
468
ty, // `Self` type
470
469
|impl_def_id| {
471
- let impl_args = self . fresh_args_for_item ( DUMMY_SP , impl_def_id) ;
470
+ let impl_args = ty:: GenericArgs :: for_item (
471
+ self . infcx . tcx ,
472
+ impl_def_id,
473
+ |param, _| {
474
+ // We don't want to name the arguments, we just want to give an
475
+ // idea of what the syntax is.
476
+ match param. kind {
477
+ ty:: GenericParamDefKind :: Lifetime => {
478
+ self . infcx . tcx . lifetimes . re_erased . into ( )
479
+ }
480
+ ty:: GenericParamDefKind :: Type { .. } => {
481
+ self . next_ty_var ( DUMMY_SP ) . into ( )
482
+ }
483
+ ty:: GenericParamDefKind :: Const { .. } => {
484
+ self . next_const_var ( DUMMY_SP ) . into ( )
485
+ }
486
+ }
487
+ } ,
488
+ ) ;
472
489
let impl_trait_ref = self
473
490
. infcx
474
491
. tcx
@@ -521,15 +538,18 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
521
538
// The method isn't in this `impl`? Not useful to us then.
522
539
return ;
523
540
} ;
541
+ let Some ( trait_assoc_item) = assoc. trait_item_def_id else {
542
+ return ;
543
+ } ;
524
544
// Let's ignore the generic params and replace them with `_` in the
525
545
// suggested path.
526
- let identity_method = ty :: GenericArgs :: for_item (
546
+ let trait_assoc_substs = impl_trait_ref . args . extend_to (
527
547
self . infcx . tcx ,
528
- assoc . def_id ,
529
- |param , _| {
548
+ trait_assoc_item ,
549
+ |def , _| {
530
550
// We don't want to name the arguments, we just want to give an
531
551
// idea of what the syntax is.
532
- match param . kind {
552
+ match def . kind {
533
553
ty:: GenericParamDefKind :: Lifetime => {
534
554
self . infcx . tcx . lifetimes . re_erased . into ( )
535
555
}
@@ -542,10 +562,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
542
562
}
543
563
} ,
544
564
) ;
565
+ let identity_method =
566
+ impl_args. rebase_onto ( self . infcx . tcx , def_id, trait_assoc_substs) ;
545
567
let fn_sig = self
546
568
. infcx
547
569
. tcx
548
- . fn_sig ( assoc . def_id )
570
+ . fn_sig ( def_id)
549
571
. instantiate ( self . infcx . tcx , identity_method) ;
550
572
let ret = fn_sig. skip_binder ( ) . output ( ) ;
551
573
paths. push ( format ! ( "{ret}" ) ) ;
@@ -676,15 +698,32 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
676
698
} ;
677
699
678
700
let mut paths = vec ! [ ] ;
679
- let param_env = ty:: ParamEnv :: reveal_all ( ) ;
680
701
let name = self . infcx . tcx . item_name ( def_id) ;
681
702
// Look for all the possible implementations to suggest, otherwise we'll show
682
703
// just suggest the syntax for the fully qualified path with placeholders.
683
704
self . infcx . tcx . for_each_relevant_impl (
684
705
self . infcx . tcx . parent ( def_id) , // Trait `DefId`
685
706
args. type_at ( 0 ) , // `Self` type
686
707
|impl_def_id| {
687
- let impl_args = self . fresh_args_for_item ( DUMMY_SP , impl_def_id) ;
708
+ let impl_args = ty:: GenericArgs :: for_item (
709
+ self . infcx . tcx ,
710
+ impl_def_id,
711
+ |param, _| {
712
+ // We don't want to name the arguments, we just want to give an
713
+ // idea of what the syntax is.
714
+ match param. kind {
715
+ ty:: GenericParamDefKind :: Lifetime => {
716
+ self . infcx . tcx . lifetimes . re_erased . into ( )
717
+ }
718
+ ty:: GenericParamDefKind :: Type { .. } => {
719
+ self . next_ty_var ( DUMMY_SP ) . into ( )
720
+ }
721
+ ty:: GenericParamDefKind :: Const { .. } => {
722
+ self . next_const_var ( DUMMY_SP ) . into ( )
723
+ }
724
+ }
725
+ } ,
726
+ ) ;
688
727
let impl_trait_ref = self
689
728
. infcx
690
729
. tcx
@@ -737,15 +776,16 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
737
776
// The method isn't in this `impl`? Not useful to us then.
738
777
return ;
739
778
} ;
740
- // Let's ignore the generic params and replace them with `_` in the
741
- // suggested path.
742
- let identity_method = ty:: GenericArgs :: for_item (
779
+ let Some ( trait_assoc_item) = assoc. trait_item_def_id else {
780
+ return ;
781
+ } ;
782
+ let trait_assoc_substs = impl_trait_ref. args . extend_to (
743
783
self . infcx . tcx ,
744
- assoc . def_id ,
745
- |param , _| {
784
+ trait_assoc_item ,
785
+ |def , _| {
746
786
// We don't want to name the arguments, we just want to give an
747
787
// idea of what the syntax is.
748
- match param . kind {
788
+ match def . kind {
749
789
ty:: GenericParamDefKind :: Lifetime => {
750
790
self . infcx . tcx . lifetimes . re_erased . into ( )
751
791
}
@@ -758,8 +798,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
758
798
}
759
799
} ,
760
800
) ;
801
+ let identity_method =
802
+ args. rebase_onto ( self . infcx . tcx , def_id, trait_assoc_substs) ;
761
803
let mut printer = fmt_printer ( self , Namespace :: ValueNS ) ;
762
- printer. print_def_path ( assoc . def_id , identity_method) . unwrap ( ) ;
804
+ printer. print_def_path ( def_id, identity_method) . unwrap ( ) ;
763
805
paths. push ( printer. into_buffer ( ) ) ;
764
806
} ,
765
807
) ;
0 commit comments