@@ -2730,7 +2730,7 @@ pub(crate) fn import_candidates(
2730
2730
) ;
2731
2731
}
2732
2732
2733
- type PathString < ' a > = ( String , & ' a str , Option < DefId > , & ' a Option < String > , bool ) ;
2733
+ type PathString < ' a > = ( String , & ' a str , Option < Span > , & ' a Option < String > , bool ) ;
2734
2734
2735
2735
/// When an entity with a given name is not available in scope, we search for
2736
2736
/// entities with that name in all crates. This method allows outputting the
@@ -2762,7 +2762,7 @@ fn show_candidates(
2762
2762
accessible_path_strings. push ( (
2763
2763
pprust:: path_to_string ( & c. path ) ,
2764
2764
c. descr ,
2765
- c. did ,
2765
+ c. did . and_then ( |did| Some ( tcx . source_span ( did . as_local ( ) ? ) ) ) ,
2766
2766
& c. note ,
2767
2767
c. via_import ,
2768
2768
) )
@@ -2771,7 +2771,7 @@ fn show_candidates(
2771
2771
inaccessible_path_strings. push ( (
2772
2772
pprust:: path_to_string ( & c. path ) ,
2773
2773
c. descr ,
2774
- c. did ,
2774
+ c. did . and_then ( |did| Some ( tcx . source_span ( did . as_local ( ) ? ) ) ) ,
2775
2775
& c. note ,
2776
2776
c. via_import ,
2777
2777
) )
@@ -2889,15 +2889,14 @@ fn show_candidates(
2889
2889
} else if !( inaccessible_path_strings. is_empty ( ) || matches ! ( mode, DiagMode :: Import { .. } ) ) {
2890
2890
let prefix =
2891
2891
if let DiagMode :: Pattern = mode { "you might have meant to match on " } else { "" } ;
2892
- if let [ ( name, descr, def_id , note, _) ] = & inaccessible_path_strings[ ..] {
2892
+ if let [ ( name, descr, source_span , note, _) ] = & inaccessible_path_strings[ ..] {
2893
2893
let msg = format ! (
2894
2894
"{prefix}{descr} `{name}`{} exists but is inaccessible" ,
2895
2895
if let DiagMode :: Pattern = mode { ", which" } else { "" }
2896
2896
) ;
2897
2897
2898
- if let Some ( local_def_id) = def_id. and_then ( |did| did. as_local ( ) ) {
2899
- let span = tcx. source_span ( local_def_id) ;
2900
- let span = tcx. sess . source_map ( ) . guess_head_span ( span) ;
2898
+ if let Some ( source_span) = source_span {
2899
+ let span = tcx. sess . source_map ( ) . guess_head_span ( * source_span) ;
2901
2900
let mut multi_span = MultiSpan :: from_span ( span) ;
2902
2901
multi_span. push_span_label ( span, "not accessible" ) ;
2903
2902
err. span_note ( multi_span, msg) ;
@@ -2925,10 +2924,9 @@ fn show_candidates(
2925
2924
let mut has_colon = false ;
2926
2925
2927
2926
let mut spans = Vec :: new ( ) ;
2928
- for ( name, _, def_id, _, _) in & inaccessible_path_strings {
2929
- if let Some ( local_def_id) = def_id. and_then ( |did| did. as_local ( ) ) {
2930
- let span = tcx. source_span ( local_def_id) ;
2931
- let span = tcx. sess . source_map ( ) . guess_head_span ( span) ;
2927
+ for ( name, _, source_span, _, _) in & inaccessible_path_strings {
2928
+ if let Some ( source_span) = source_span {
2929
+ let span = tcx. sess . source_map ( ) . guess_head_span ( * source_span) ;
2932
2930
spans. push ( ( name, span) ) ;
2933
2931
} else {
2934
2932
if !has_colon {
0 commit comments