@@ -2,7 +2,8 @@ use rustc_ast::expand::StrippedCfgItem;
2
2
use rustc_ast:: ptr:: P ;
3
3
use rustc_ast:: visit:: { self , Visitor } ;
4
4
use rustc_ast:: {
5
- self as ast, CRATE_NODE_ID , Crate , ItemKind , MetaItemInner , MetaItemKind , ModKind , NodeId , Path ,
5
+ self as ast, CRATE_NODE_ID , Crate , ItemKind , MetaItemInner , MetaItemKind , ModKind , NodeId ,
6
+ Path , join_path_idents,
6
7
} ;
7
8
use rustc_ast_pretty:: pprust;
8
9
use rustc_attr_data_structures:: { self as attr, AttributeKind , Stability , find_attr} ;
@@ -2019,7 +2020,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
2019
2020
}
2020
2021
}
2021
2022
2022
- let mut sugg_paths = vec ! [ ] ;
2023
+ let mut sugg_paths: Vec < ( Vec < Ident > , bool ) > = vec ! [ ] ;
2023
2024
if let Some ( mut def_id) = res. opt_def_id ( ) {
2024
2025
// We can't use `def_path_str` in resolve.
2025
2026
let mut path = vec ! [ def_id] ;
@@ -2032,16 +2033,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
2032
2033
}
2033
2034
}
2034
2035
// We will only suggest importing directly if it is accessible through that path.
2035
- let path_names: Option < Vec < String > > = path
2036
+ let path_names: Option < Vec < Ident > > = path
2036
2037
. iter ( )
2037
2038
. rev ( )
2038
2039
. map ( |def_id| {
2039
- self . tcx . opt_item_name ( * def_id) . map ( |n | {
2040
- if def_id. is_top_level_module ( ) {
2041
- "crate" . to_string ( )
2040
+ self . tcx . opt_item_name ( * def_id) . map ( |name | {
2041
+ Ident :: with_dummy_span ( if def_id. is_top_level_module ( ) {
2042
+ kw :: Crate
2042
2043
} else {
2043
- n . to_string ( )
2044
- }
2044
+ name
2045
+ } )
2045
2046
} )
2046
2047
} )
2047
2048
. collect ( ) ;
@@ -2085,13 +2086,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
2085
2086
match binding. kind {
2086
2087
NameBindingKind :: Import { import, .. } => {
2087
2088
for segment in import. module_path . iter ( ) . skip ( 1 ) {
2088
- path. push ( segment. ident . to_string ( ) ) ;
2089
+ path. push ( segment. ident ) ;
2089
2090
}
2090
2091
sugg_paths. push ( (
2091
- path. iter ( )
2092
- . cloned ( )
2093
- . chain ( vec ! [ ident. to_string( ) ] . into_iter ( ) )
2094
- . collect :: < Vec < _ > > ( ) ,
2092
+ path. iter ( ) . cloned ( ) . chain ( vec ! [ ident] . into_iter ( ) ) . collect :: < Vec < _ > > ( ) ,
2095
2093
true , // re-export
2096
2094
) ) ;
2097
2095
}
@@ -2127,7 +2125,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
2127
2125
err. subdiagnostic ( note) ;
2128
2126
}
2129
2127
// We prioritize shorter paths, non-core imports and direct imports over the alternatives.
2130
- sugg_paths. sort_by_key ( |( p, reexport) | ( p. len ( ) , p[ 0 ] == " core" , * reexport) ) ;
2128
+ sugg_paths. sort_by_key ( |( p, reexport) | ( p. len ( ) , p[ 0 ] . name == sym :: core, * reexport) ) ;
2131
2129
for ( sugg, reexport) in sugg_paths {
2132
2130
if not_publicly_reexported {
2133
2131
break ;
@@ -2137,7 +2135,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
2137
2135
// `tests/ui/imports/issue-55884-2.rs`
2138
2136
continue ;
2139
2137
}
2140
- let path = sugg . join ( "::" ) ;
2138
+ let path = join_path_idents ( sugg ) ;
2141
2139
let sugg = if reexport {
2142
2140
errors:: ImportIdent :: ThroughReExport { span : dedup_span, ident, path }
2143
2141
} else {
0 commit comments