@@ -3,7 +3,8 @@ use rustc_data_structures::sorted_map::SortedMap;
3
3
use rustc_data_structures:: unord:: UnordMap ;
4
4
use rustc_errors:: codes:: * ;
5
5
use 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,
7
8
} ;
8
9
use rustc_hir:: def:: { CtorOf , DefKind , Res } ;
9
10
use rustc_hir:: def_id:: DefId ;
@@ -443,7 +444,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
443
444
span,
444
445
& type_names,
445
446
& [ path_str] ,
446
- item_segment. ident . name ,
447
+ item_segment. ident ,
447
448
assoc_tag,
448
449
)
449
450
}
@@ -552,12 +553,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
552
553
553
554
let traits: Vec < _ > = self . probe_traits_that_match_assoc_ty ( self_ty, ident) ;
554
555
555
- // Don't print `ty::Error` to the user.
556
556
self . report_ambiguous_assoc_item_path (
557
557
span,
558
558
& [ self_ty. to_string ( ) ] ,
559
559
& traits,
560
- ident. name ,
560
+ ident,
561
561
assoc_tag,
562
562
)
563
563
}
@@ -568,7 +568,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
568
568
span : Span ,
569
569
types : & [ String ] ,
570
570
traits : & [ String ] ,
571
- name : Symbol ,
571
+ ident : Ident ,
572
572
assoc_tag : ty:: AssocTag ,
573
573
) -> ErrorGuaranteed {
574
574
let kind_str = assoc_tag_str ( assoc_tag) ;
@@ -588,83 +588,88 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
588
588
Applicability :: MachineApplicable ,
589
589
) ;
590
590
} else {
591
+ let sugg_sp = span. until ( ident. span ) ;
592
+
591
593
let mut types = types. to_vec ( ) ;
592
594
types. sort ( ) ;
593
595
let mut traits = traits. to_vec ( ) ;
594
596
traits. sort ( ) ;
595
597
match ( & types[ ..] , & traits[ ..] ) {
596
598
( [ ] , [ ] ) => {
597
599
err. span_suggestion_verbose (
598
- span ,
600
+ sugg_sp ,
599
601
format ! (
600
602
"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 \
602
604
fully-qualified path",
603
605
) ,
604
- format ! ( "<Type as Trait>::{name}" ) ,
606
+ "<Type as Trait>::" ,
605
607
Applicability :: HasPlaceholders ,
606
608
) ;
607
609
}
608
610
( [ ] , [ trait_str] ) => {
609
611
err. span_suggestion_verbose (
610
- span ,
612
+ sugg_sp ,
611
613
format ! (
612
614
"if there were a type named `Example` that implemented `{trait_str}`, \
613
615
you could use the fully-qualified path",
614
616
) ,
615
- format ! ( "<Example as {trait_str}>::{name} " ) ,
617
+ format ! ( "<Example as {trait_str}>::" ) ,
616
618
Applicability :: HasPlaceholders ,
617
619
) ;
618
620
}
619
621
( [ ] , traits) => {
620
- err. span_suggestions (
621
- span ,
622
+ err. span_suggestions_with_style (
623
+ sugg_sp ,
622
624
format ! (
623
625
"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 \
625
627
fully-qualified path",
626
628
) ,
627
- traits. iter ( ) . map ( |trait_str| format ! ( "<Example as {trait_str}>::{name} " ) ) ,
629
+ traits. iter ( ) . map ( |trait_str| format ! ( "<Example as {trait_str}>::" ) ) ,
628
630
Applicability :: HasPlaceholders ,
631
+ SuggestionStyle :: ShowAlways ,
629
632
) ;
630
633
}
631
634
( [ type_str] , [ ] ) => {
632
635
err. span_suggestion_verbose (
633
- span ,
636
+ sugg_sp ,
634
637
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 }` \
636
639
implemented for `{type_str}`, you could use the fully-qualified path",
637
640
) ,
638
- format ! ( "<{type_str} as Example>::{name} " ) ,
641
+ format ! ( "<{type_str} as Example>::" ) ,
639
642
Applicability :: HasPlaceholders ,
640
643
) ;
641
644
}
642
645
( types, [ ] ) => {
643
- err. span_suggestions (
644
- span ,
646
+ err. span_suggestions_with_style (
647
+ sugg_sp ,
645
648
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 }` \
647
650
implemented for one of the types, you could use the fully-qualified \
648
651
path",
649
652
) ,
650
653
types
651
654
. into_iter ( )
652
- . map ( |type_str| format ! ( "<{type_str} as Example>::{name} " ) ) ,
655
+ . map ( |type_str| format ! ( "<{type_str} as Example>::" ) ) ,
653
656
Applicability :: HasPlaceholders ,
657
+ SuggestionStyle :: ShowAlways ,
654
658
) ;
655
659
}
656
660
( types, traits) => {
657
661
let mut suggestions = vec ! [ ] ;
658
662
for type_str in types {
659
663
for trait_str in traits {
660
- suggestions. push ( format ! ( "<{type_str} as {trait_str}>::{name} " ) ) ;
664
+ suggestions. push ( format ! ( "<{type_str} as {trait_str}>::" ) ) ;
661
665
}
662
666
}
663
- err. span_suggestions (
664
- span ,
667
+ err. span_suggestions_with_style (
668
+ sugg_sp ,
665
669
"use fully-qualified syntax" ,
666
670
suggestions,
667
671
Applicability :: MachineApplicable ,
672
+ SuggestionStyle :: ShowAlways ,
668
673
) ;
669
674
}
670
675
}
0 commit comments