11use rustc_ast:: ptr:: P ;
22use rustc_ast:: visit:: { self , Visitor } ;
3- use rustc_ast:: { self as ast, CRATE_NODE_ID , Crate , ItemKind , ModKind , NodeId , Path } ;
3+ use rustc_ast:: {
4+ self as ast, CRATE_NODE_ID , Crate , ItemKind , ModKind , NodeId , Path , join_path_idents,
5+ } ;
46use rustc_ast_pretty:: pprust;
57use rustc_attr_data_structures:: {
68 self as attr, AttributeKind , CfgEntry , Stability , StrippedCfgItem , find_attr,
@@ -2018,7 +2020,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20182020 }
20192021 }
20202022
2021- let mut sugg_paths = vec ! [ ] ;
2023+ let mut sugg_paths: Vec < ( Vec < Ident > , bool ) > = vec ! [ ] ;
20222024 if let Some ( mut def_id) = res. opt_def_id ( ) {
20232025 // We can't use `def_path_str` in resolve.
20242026 let mut path = vec ! [ def_id] ;
@@ -2031,16 +2033,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20312033 }
20322034 }
20332035 // We will only suggest importing directly if it is accessible through that path.
2034- let path_names: Option < Vec < String > > = path
2036+ let path_names: Option < Vec < Ident > > = path
20352037 . iter ( )
20362038 . rev ( )
20372039 . map ( |def_id| {
2038- self . tcx . opt_item_name ( * def_id) . map ( |n | {
2039- if def_id. is_top_level_module ( ) {
2040- "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
20412043 } else {
2042- n . to_string ( )
2043- }
2044+ name
2045+ } )
20442046 } )
20452047 } )
20462048 . collect ( ) ;
@@ -2084,13 +2086,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20842086 match binding. kind {
20852087 NameBindingKind :: Import { import, .. } => {
20862088 for segment in import. module_path . iter ( ) . skip ( 1 ) {
2087- path. push ( segment. ident . to_string ( ) ) ;
2089+ path. push ( segment. ident ) ;
20882090 }
20892091 sugg_paths. push ( (
2090- path. iter ( )
2091- . cloned ( )
2092- . chain ( vec ! [ ident. to_string( ) ] . into_iter ( ) )
2093- . collect :: < Vec < _ > > ( ) ,
2092+ path. iter ( ) . cloned ( ) . chain ( std:: iter:: once ( ident) ) . collect :: < Vec < _ > > ( ) ,
20942093 true , // re-export
20952094 ) ) ;
20962095 }
@@ -2126,7 +2125,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
21262125 err. subdiagnostic ( note) ;
21272126 }
21282127 // We prioritize shorter paths, non-core imports and direct imports over the alternatives.
2129- 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) ) ;
21302129 for ( sugg, reexport) in sugg_paths {
21312130 if not_publicly_reexported {
21322131 break ;
@@ -2136,7 +2135,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
21362135 // `tests/ui/imports/issue-55884-2.rs`
21372136 continue ;
21382137 }
2139- let path = sugg . join ( "::" ) ;
2138+ let path = join_path_idents ( sugg ) ;
21402139 let sugg = if reexport {
21412140 errors:: ImportIdent :: ThroughReExport { span : dedup_span, ident, path }
21422141 } else {
0 commit comments