@@ -2,7 +2,8 @@ use rustc_ast::expand::StrippedCfgItem;
22use rustc_ast:: ptr:: P ;
33use rustc_ast:: visit:: { self , Visitor } ;
44use 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,
67} ;
78use rustc_ast_pretty:: pprust;
89use rustc_attr_data_structures:: { self as attr, AttributeKind , Stability , find_attr} ;
@@ -2019,7 +2020,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20192020 }
20202021 }
20212022
2022- let mut sugg_paths = vec ! [ ] ;
2023+ let mut sugg_paths: Vec < ( Vec < Ident > , bool ) > = vec ! [ ] ;
20232024 if let Some ( mut def_id) = res. opt_def_id ( ) {
20242025 // We can't use `def_path_str` in resolve.
20252026 let mut path = vec ! [ def_id] ;
@@ -2032,16 +2033,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20322033 }
20332034 }
20342035 // 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
20362037 . iter ( )
20372038 . rev ( )
20382039 . 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
20422043 } else {
2043- n . to_string ( )
2044- }
2044+ name
2045+ } )
20452046 } )
20462047 } )
20472048 . collect ( ) ;
@@ -2085,13 +2086,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20852086 match binding. kind {
20862087 NameBindingKind :: Import { import, .. } => {
20872088 for segment in import. module_path . iter ( ) . skip ( 1 ) {
2088- path. push ( segment. ident . to_string ( ) ) ;
2089+ path. push ( segment. ident ) ;
20892090 }
20902091 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 < _ > > ( ) ,
20952093 true , // re-export
20962094 ) ) ;
20972095 }
@@ -2127,7 +2125,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
21272125 err. subdiagnostic ( note) ;
21282126 }
21292127 // 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) ) ;
21312129 for ( sugg, reexport) in sugg_paths {
21322130 if not_publicly_reexported {
21332131 break ;
@@ -2137,7 +2135,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
21372135 // `tests/ui/imports/issue-55884-2.rs`
21382136 continue ;
21392137 }
2140- let path = sugg . join ( "::" ) ;
2138+ let path = join_path_idents ( sugg ) ;
21412139 let sugg = if reexport {
21422140 errors:: ImportIdent :: ThroughReExport { span : dedup_span, ident, path }
21432141 } else {
0 commit comments