@@ -205,7 +205,6 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinte
205205        } 
206206    } ; 
207207    printer. ty_infer_name_resolver  = Some ( Box :: new ( ty_getter) ) ; 
208-     printer. for_suggestion  = true ; 
209208    let  const_getter =
210209        move  |ct_vid| Some ( infcx. tcx . item_name ( infcx. const_var_origin ( ct_vid) ?. param_def_id ?) ) ; 
211210    printer. const_infer_name_resolver  = Some ( Box :: new ( const_getter) ) ; 
@@ -419,6 +418,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
419418        arg :  GenericArg < ' tcx > , 
420419        error_code :  TypeAnnotationNeeded , 
421420        should_label_span :  bool , 
421+         param_env :  ty:: ParamEnv < ' tcx > , 
422422    )  -> Diag < ' a >  { 
423423        let  arg = self . resolve_vars_if_possible ( arg) ; 
424424        let  arg_data = self . extract_inference_diagnostics_data ( arg,  None ) ; 
@@ -454,7 +454,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
454454        match  kind { 
455455            InferSourceKind :: LetBinding  {  insert_span,  pattern_name,  ty,  def_id,  hir_id }  => { 
456456                let  mut  paths = vec ! [ ] ; 
457-                 let  param_env = ty:: ParamEnv :: reveal_all ( ) ; 
458457                if  let  Some ( def_id)  = def_id
459458                    && let  name = self . infcx . tcx . item_name ( def_id) 
460459                    && let  Some ( hir_id)  = hir_id
@@ -468,7 +467,25 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
468467                        self . infcx . tcx . parent ( def_id) ,  // Trait `DefId` 
469468                        ty,                             // `Self` type 
470469                        |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+                             ) ; 
472489                            let  impl_trait_ref = self 
473490                                . infcx 
474491                                . tcx 
@@ -521,15 +538,18 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
521538                                // The method isn't in this `impl`? Not useful to us then. 
522539                                return ; 
523540                            } ; 
541+                             let  Some ( trait_assoc_item)  = assoc. trait_item_def_id  else  { 
542+                                 return ; 
543+                             } ; 
524544                            // Let's ignore the generic params and replace them with `_` in the 
525545                            // suggested path. 
526-                             let  identity_method  = ty :: GenericArgs :: for_item ( 
546+                             let  trait_assoc_substs  = impl_trait_ref . args . extend_to ( 
527547                                self . infcx . tcx , 
528-                                 assoc . def_id , 
529-                                 |param ,  _| { 
548+                                 trait_assoc_item , 
549+                                 |def ,  _| { 
530550                                    // We don't want to name the arguments, we just want to give an 
531551                                    // idea of what the syntax is. 
532-                                     match  param . kind  { 
552+                                     match  def . kind  { 
533553                                        ty:: GenericParamDefKind :: Lifetime  => { 
534554                                            self . infcx . tcx . lifetimes . re_erased . into ( ) 
535555                                        } 
@@ -542,10 +562,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
542562                                    } 
543563                                } , 
544564                            ) ; 
565+                             let  identity_method =
566+                                 impl_args. rebase_onto ( self . infcx . tcx ,  def_id,  trait_assoc_substs) ; 
545567                            let  fn_sig = self 
546568                                . infcx 
547569                                . tcx 
548-                                 . fn_sig ( assoc . def_id ) 
570+                                 . fn_sig ( def_id) 
549571                                . instantiate ( self . infcx . tcx ,  identity_method) ; 
550572                            let  ret = fn_sig. skip_binder ( ) . output ( ) ; 
551573                            paths. push ( format ! ( "{ret}" ) ) ; 
@@ -676,15 +698,32 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
676698                    } ; 
677699
678700                    let  mut  paths = vec ! [ ] ; 
679-                     let  param_env = ty:: ParamEnv :: reveal_all ( ) ; 
680701                    let  name = self . infcx . tcx . item_name ( def_id) ; 
681702                    // Look for all the possible implementations to suggest, otherwise we'll show 
682703                    // just suggest the syntax for the fully qualified path with placeholders. 
683704                    self . infcx . tcx . for_each_relevant_impl ( 
684705                        self . infcx . tcx . parent ( def_id) ,  // Trait `DefId` 
685706                        args. type_at ( 0 ) ,                // `Self` type 
686707                        |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+                             ) ; 
688727                            let  impl_trait_ref = self 
689728                                . infcx 
690729                                . tcx 
@@ -737,15 +776,16 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
737776                                // The method isn't in this `impl`? Not useful to us then. 
738777                                return ; 
739778                            } ; 
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 ( 
743783                                self . infcx . tcx , 
744-                                 assoc . def_id , 
745-                                 |param ,  _| { 
784+                                 trait_assoc_item , 
785+                                 |def ,  _| { 
746786                                    // We don't want to name the arguments, we just want to give an 
747787                                    // idea of what the syntax is. 
748-                                     match  param . kind  { 
788+                                     match  def . kind  { 
749789                                        ty:: GenericParamDefKind :: Lifetime  => { 
750790                                            self . infcx . tcx . lifetimes . re_erased . into ( ) 
751791                                        } 
@@ -758,8 +798,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
758798                                    } 
759799                                } , 
760800                            ) ; 
801+                             let  identity_method =
802+                                 args. rebase_onto ( self . infcx . tcx ,  def_id,  trait_assoc_substs) ; 
761803                            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 ( ) ; 
763805                            paths. push ( printer. into_buffer ( ) ) ; 
764806                        } , 
765807                    ) ; 
0 commit comments