@@ -3,7 +3,8 @@ use rustc_data_structures::sorted_map::SortedMap;
33use rustc_data_structures:: unord:: UnordMap ;
44use rustc_errors:: codes:: * ;
55use rustc_errors:: {
6- Applicability , Diag , ErrorGuaranteed , MultiSpan , listify, pluralize, struct_span_code_err,
6+ Applicability , Diag , ErrorGuaranteed , MultiSpan , SuggestionStyle , listify, pluralize,
7+ struct_span_code_err,
78} ;
89use rustc_hir:: def:: { CtorOf , DefKind , Res } ;
910use rustc_hir:: def_id:: DefId ;
@@ -443,7 +444,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
443444 span,
444445 & type_names,
445446 & [ path_str] ,
446- item_segment. ident . name ,
447+ item_segment. ident ,
447448 assoc_tag,
448449 )
449450 }
@@ -552,12 +553,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
552553
553554 let traits: Vec < _ > = self . probe_traits_that_match_assoc_ty ( self_ty, ident) ;
554555
555- // Don't print `ty::Error` to the user.
556556 self . report_ambiguous_assoc_item_path (
557557 span,
558558 & [ self_ty. to_string ( ) ] ,
559559 & traits,
560- ident. name ,
560+ ident,
561561 assoc_tag,
562562 )
563563 }
@@ -568,7 +568,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
568568 span : Span ,
569569 types : & [ String ] ,
570570 traits : & [ String ] ,
571- name : Symbol ,
571+ ident : Ident ,
572572 assoc_tag : ty:: AssocTag ,
573573 ) -> ErrorGuaranteed {
574574 let kind_str = assoc_tag_str ( assoc_tag) ;
@@ -588,83 +588,88 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
588588 Applicability :: MachineApplicable ,
589589 ) ;
590590 } else {
591+ let sugg_sp = span. until ( ident. span ) ;
592+
591593 let mut types = types. to_vec ( ) ;
592594 types. sort ( ) ;
593595 let mut traits = traits. to_vec ( ) ;
594596 traits. sort ( ) ;
595597 match ( & types[ ..] , & traits[ ..] ) {
596598 ( [ ] , [ ] ) => {
597599 err. span_suggestion_verbose (
598- span ,
600+ sugg_sp ,
599601 format ! (
600602 "if there were a type named `Type` that implements a trait named \
601- `Trait` with associated {kind_str} `{name }`, you could use the \
603+ `Trait` with associated {kind_str} `{ident }`, you could use the \
602604 fully-qualified path",
603605 ) ,
604- format ! ( "<Type as Trait>::{name}" ) ,
606+ "<Type as Trait>::" ,
605607 Applicability :: HasPlaceholders ,
606608 ) ;
607609 }
608610 ( [ ] , [ trait_str] ) => {
609611 err. span_suggestion_verbose (
610- span ,
612+ sugg_sp ,
611613 format ! (
612614 "if there were a type named `Example` that implemented `{trait_str}`, \
613615 you could use the fully-qualified path",
614616 ) ,
615- format ! ( "<Example as {trait_str}>::{name} " ) ,
617+ format ! ( "<Example as {trait_str}>::" ) ,
616618 Applicability :: HasPlaceholders ,
617619 ) ;
618620 }
619621 ( [ ] , traits) => {
620- err. span_suggestions (
621- span ,
622+ err. span_suggestions_with_style (
623+ sugg_sp ,
622624 format ! (
623625 "if there were a type named `Example` that implemented one of the \
624- traits with associated {kind_str} `{name }`, you could use the \
626+ traits with associated {kind_str} `{ident }`, you could use the \
625627 fully-qualified path",
626628 ) ,
627- traits. iter ( ) . map ( |trait_str| format ! ( "<Example as {trait_str}>::{name} " ) ) ,
629+ traits. iter ( ) . map ( |trait_str| format ! ( "<Example as {trait_str}>::" ) ) ,
628630 Applicability :: HasPlaceholders ,
631+ SuggestionStyle :: ShowAlways ,
629632 ) ;
630633 }
631634 ( [ type_str] , [ ] ) => {
632635 err. span_suggestion_verbose (
633- span ,
636+ sugg_sp ,
634637 format ! (
635- "if there were a trait named `Example` with associated {kind_str} `{name }` \
638+ "if there were a trait named `Example` with associated {kind_str} `{ident }` \
636639 implemented for `{type_str}`, you could use the fully-qualified path",
637640 ) ,
638- format ! ( "<{type_str} as Example>::{name} " ) ,
641+ format ! ( "<{type_str} as Example>::" ) ,
639642 Applicability :: HasPlaceholders ,
640643 ) ;
641644 }
642645 ( types, [ ] ) => {
643- err. span_suggestions (
644- span ,
646+ err. span_suggestions_with_style (
647+ sugg_sp ,
645648 format ! (
646- "if there were a trait named `Example` with associated {kind_str} `{name }` \
649+ "if there were a trait named `Example` with associated {kind_str} `{ident }` \
647650 implemented for one of the types, you could use the fully-qualified \
648651 path",
649652 ) ,
650653 types
651654 . into_iter ( )
652- . map ( |type_str| format ! ( "<{type_str} as Example>::{name} " ) ) ,
655+ . map ( |type_str| format ! ( "<{type_str} as Example>::" ) ) ,
653656 Applicability :: HasPlaceholders ,
657+ SuggestionStyle :: ShowAlways ,
654658 ) ;
655659 }
656660 ( types, traits) => {
657661 let mut suggestions = vec ! [ ] ;
658662 for type_str in types {
659663 for trait_str in traits {
660- suggestions. push ( format ! ( "<{type_str} as {trait_str}>::{name} " ) ) ;
664+ suggestions. push ( format ! ( "<{type_str} as {trait_str}>::" ) ) ;
661665 }
662666 }
663- err. span_suggestions (
664- span ,
667+ err. span_suggestions_with_style (
668+ sugg_sp ,
665669 "use fully-qualified syntax" ,
666670 suggestions,
667671 Applicability :: MachineApplicable ,
672+ SuggestionStyle :: ShowAlways ,
668673 ) ;
669674 }
670675 }
0 commit comments