1
1
use rustc_ast:: ptr:: P ;
2
2
use 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
+ } ;
4
6
use rustc_ast_pretty:: pprust;
5
7
use rustc_attr_data_structures:: {
6
8
self as attr, AttributeKind , CfgEntry , Stability , StrippedCfgItem , find_attr,
@@ -2018,7 +2020,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
2018
2020
}
2019
2021
}
2020
2022
2021
- let mut sugg_paths = vec ! [ ] ;
2023
+ let mut sugg_paths: Vec < ( Vec < Ident > , bool ) > = vec ! [ ] ;
2022
2024
if let Some ( mut def_id) = res. opt_def_id ( ) {
2023
2025
// We can't use `def_path_str` in resolve.
2024
2026
let mut path = vec ! [ def_id] ;
@@ -2031,16 +2033,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
2031
2033
}
2032
2034
}
2033
2035
// 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
2035
2037
. iter ( )
2036
2038
. rev ( )
2037
2039
. 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
2041
2043
} else {
2042
- n . to_string ( )
2043
- }
2044
+ name
2045
+ } )
2044
2046
} )
2045
2047
} )
2046
2048
. collect ( ) ;
@@ -2084,13 +2086,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
2084
2086
match binding. kind {
2085
2087
NameBindingKind :: Import { import, .. } => {
2086
2088
for segment in import. module_path . iter ( ) . skip ( 1 ) {
2087
- path. push ( segment. ident . to_string ( ) ) ;
2089
+ path. push ( segment. ident ) ;
2088
2090
}
2089
2091
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 < _ > > ( ) ,
2094
2093
true , // re-export
2095
2094
) ) ;
2096
2095
}
@@ -2126,7 +2125,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
2126
2125
err. subdiagnostic ( note) ;
2127
2126
}
2128
2127
// 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) ) ;
2130
2129
for ( sugg, reexport) in sugg_paths {
2131
2130
if not_publicly_reexported {
2132
2131
break ;
@@ -2136,7 +2135,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
2136
2135
// `tests/ui/imports/issue-55884-2.rs`
2137
2136
continue ;
2138
2137
}
2139
- let path = sugg . join ( "::" ) ;
2138
+ let path = join_path_idents ( sugg ) ;
2140
2139
let sugg = if reexport {
2141
2140
errors:: ImportIdent :: ThroughReExport { span : dedup_span, ident, path }
2142
2141
} else {
0 commit comments