@@ -89,6 +89,7 @@ use std::sync::{Mutex, MutexGuard, OnceLock};
89
89
90
90
use itertools:: Itertools ;
91
91
use rustc_abi:: Integer ;
92
+ use rustc_ast:: join_path_syms;
92
93
use rustc_ast:: ast:: { self , LitKind , RangeLimits } ;
93
94
use rustc_attr_data_structures:: { AttributeKind , find_attr} ;
94
95
use rustc_data_structures:: fx:: FxHashMap ;
@@ -3245,8 +3246,8 @@ fn maybe_get_relative_path(from: &DefPath, to: &DefPath, max_super: usize) -> St
3245
3246
// a::b::c ::d::sym refers to
3246
3247
// e::f::sym:: ::
3247
3248
// result should be super::super::super::super::e::f
3248
- if let DefPathData :: TypeNs ( s ) = l {
3249
- path. push ( s . to_string ( ) ) ;
3249
+ if let DefPathData :: TypeNs ( sym ) = l {
3250
+ path. push ( sym ) ;
3250
3251
}
3251
3252
if let DefPathData :: TypeNs ( _) = r {
3252
3253
go_up_by += 1 ;
@@ -3256,7 +3257,7 @@ fn maybe_get_relative_path(from: &DefPath, to: &DefPath, max_super: usize) -> St
3256
3257
// a::b::sym:: :: refers to
3257
3258
// c::d::e ::f::sym
3258
3259
// when looking at `f`
3259
- Left ( DefPathData :: TypeNs ( sym) ) => path. push ( sym. to_string ( ) ) ,
3260
+ Left ( DefPathData :: TypeNs ( sym) ) => path. push ( sym) ,
3260
3261
// consider:
3261
3262
// a::b::c ::d::sym refers to
3262
3263
// e::f::sym:: ::
@@ -3268,17 +3269,17 @@ fn maybe_get_relative_path(from: &DefPath, to: &DefPath, max_super: usize) -> St
3268
3269
3269
3270
if go_up_by > max_super {
3270
3271
// `super` chain would be too long, just use the absolute path instead
3271
- once ( String :: from ( "crate" ) )
3272
- . chain ( to. data . iter ( ) . filter_map ( |el| {
3272
+ join_path_syms (
3273
+ once ( kw :: Crate ) . chain ( to. data . iter ( ) . filter_map ( |el| {
3273
3274
if let DefPathData :: TypeNs ( sym) = el. data {
3274
- Some ( sym. to_string ( ) )
3275
+ Some ( sym)
3275
3276
} else {
3276
3277
None
3277
3278
}
3278
3279
} ) )
3279
- . join ( "::" )
3280
+ )
3280
3281
} else {
3281
- repeat_n ( String :: from ( "super" ) , go_up_by) . chain ( path) . join ( "::" )
3282
+ join_path_syms ( repeat_n ( kw :: Super , go_up_by) . chain ( path) )
3282
3283
}
3283
3284
}
3284
3285
0 commit comments