@@ -89,6 +89,7 @@ use std::sync::{Mutex, MutexGuard, OnceLock};
8989
9090use itertools:: Itertools ;
9191use rustc_abi:: Integer ;
92+ use rustc_ast:: join_path_syms;
9293use rustc_ast:: ast:: { self , LitKind , RangeLimits } ;
9394use rustc_attr_data_structures:: { AttributeKind , find_attr} ;
9495use rustc_data_structures:: fx:: FxHashMap ;
@@ -3245,8 +3246,8 @@ fn maybe_get_relative_path(from: &DefPath, to: &DefPath, max_super: usize) -> St
32453246 // a::b::c ::d::sym refers to
32463247 // e::f::sym:: ::
32473248 // 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 ) ;
32503251 }
32513252 if let DefPathData :: TypeNs ( _) = r {
32523253 go_up_by += 1 ;
@@ -3256,7 +3257,7 @@ fn maybe_get_relative_path(from: &DefPath, to: &DefPath, max_super: usize) -> St
32563257 // a::b::sym:: :: refers to
32573258 // c::d::e ::f::sym
32583259 // when looking at `f`
3259- Left ( DefPathData :: TypeNs ( sym) ) => path. push ( sym. to_string ( ) ) ,
3260+ Left ( DefPathData :: TypeNs ( sym) ) => path. push ( sym) ,
32603261 // consider:
32613262 // a::b::c ::d::sym refers to
32623263 // e::f::sym:: ::
@@ -3268,17 +3269,17 @@ fn maybe_get_relative_path(from: &DefPath, to: &DefPath, max_super: usize) -> St
32683269
32693270 if go_up_by > max_super {
32703271 // `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| {
32733274 if let DefPathData :: TypeNs ( sym) = el. data {
3274- Some ( sym. to_string ( ) )
3275+ Some ( sym)
32753276 } else {
32763277 None
32773278 }
32783279 } ) )
3279- . join ( "::" )
3280+ )
32803281 } 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) )
32823283 }
32833284}
32843285
0 commit comments