File tree Expand file tree Collapse file tree 4 files changed +14
-27
lines changed Expand file tree Collapse file tree 4 files changed +14
-27
lines changed Original file line number Diff line number Diff line change @@ -105,17 +105,6 @@ impl Path {
105105 }
106106 }
107107
108- // Make a "crate root" segment for this path unless it already has it
109- // or starts with something like `self`/`super`/`$crate`/etc.
110- pub fn make_root ( & self ) -> Option < PathSegment > {
111- if let Some ( ident) = self . segments . get ( 0 ) . map ( |seg| seg. ident ) {
112- if ident. is_path_segment_keyword ( ) {
113- return None ;
114- }
115- }
116- Some ( PathSegment :: crate_root ( self . span . shrink_to_lo ( ) ) )
117- }
118-
119108 pub fn is_global ( & self ) -> bool {
120109 !self . segments . is_empty ( ) && self . segments [ 0 ] . ident . name == keywords:: PathRoot . name ( )
121110 }
@@ -144,7 +133,7 @@ impl PathSegment {
144133 pub fn from_ident ( ident : Ident ) -> Self {
145134 PathSegment { ident, id : DUMMY_NODE_ID , args : None }
146135 }
147- pub fn crate_root ( span : Span ) -> Self {
136+ pub fn path_root ( span : Span ) -> Self {
148137 PathSegment :: from_ident ( Ident :: new ( keywords:: PathRoot . name ( ) , span) )
149138 }
150139}
Original file line number Diff line number Diff line change @@ -318,9 +318,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
318318 args : Vec < ast:: GenericArg > ,
319319 bindings : Vec < ast:: TypeBinding > )
320320 -> ast:: Path {
321+ assert ! ( !idents. is_empty( ) ) ;
322+ let add_root = global && !idents[ 0 ] . is_path_segment_keyword ( ) ;
323+ let mut segments = Vec :: with_capacity ( idents. len ( ) + add_root as usize ) ;
324+ if add_root {
325+ segments. push ( ast:: PathSegment :: path_root ( span) ) ;
326+ }
321327 let last_ident = idents. pop ( ) . unwrap ( ) ;
322- let mut segments: Vec < ast:: PathSegment > = vec ! [ ] ;
323-
324328 segments. extend ( idents. into_iter ( ) . map ( |ident| {
325329 ast:: PathSegment :: from_ident ( ident. with_span_pos ( span) )
326330 } ) ) ;
@@ -334,13 +338,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
334338 id : ast:: DUMMY_NODE_ID ,
335339 args,
336340 } ) ;
337- let mut path = ast:: Path { span, segments } ;
338- if global {
339- if let Some ( seg) = path. make_root ( ) {
340- path. segments . insert ( 0 , seg) ;
341- }
342- }
343- path
341+ ast:: Path { span, segments }
344342 }
345343
346344 /// Constructs a qualified path.
Original file line number Diff line number Diff line change @@ -2082,7 +2082,7 @@ impl<'a> Parser<'a> {
20822082 let mut segments = Vec :: new ( ) ;
20832083 let mod_sep_ctxt = self . span . ctxt ( ) ;
20842084 if self . eat ( & token:: ModSep ) {
2085- segments. push ( PathSegment :: crate_root ( lo. shrink_to_lo ( ) . with_ctxt ( mod_sep_ctxt) ) ) ;
2085+ segments. push ( PathSegment :: path_root ( lo. shrink_to_lo ( ) . with_ctxt ( mod_sep_ctxt) ) ) ;
20862086 }
20872087 self . parse_path_segments ( & mut segments, style, enable_warning) ?;
20882088
@@ -7685,7 +7685,7 @@ impl<'a> Parser<'a> {
76857685 let mod_sep_ctxt = self . span . ctxt ( ) ;
76867686 if self . eat ( & token:: ModSep ) {
76877687 prefix. segments . push (
7688- PathSegment :: crate_root ( lo. shrink_to_lo ( ) . with_ctxt ( mod_sep_ctxt) )
7688+ PathSegment :: path_root ( lo. shrink_to_lo ( ) . with_ctxt ( mod_sep_ctxt) )
76897689 ) ;
76907690 }
76917691
Original file line number Diff line number Diff line change @@ -353,7 +353,7 @@ declare_keywords! {
353353 ( 2 , DollarCrate , "$crate" )
354354 ( 3 , Underscore , "_" )
355355
356- // Keywords used in the language .
356+ // Keywords that are used in stable Rust .
357357 ( 4 , As , "as" )
358358 ( 5 , Box , "box" )
359359 ( 6 , Break , "break" )
@@ -391,7 +391,7 @@ declare_keywords! {
391391 ( 38 , Where , "where" )
392392 ( 39 , While , "while" )
393393
394- // Keywords reserved for future use.
394+ // Keywords that are used in unstable Rust or reserved for future use.
395395 ( 40 , Abstract , "abstract" )
396396 ( 41 , Become , "become" )
397397 ( 42 , Do , "do" )
@@ -404,10 +404,10 @@ declare_keywords! {
404404 ( 49 , Virtual , "virtual" )
405405 ( 50 , Yield , "yield" )
406406
407- // Edition-specific keywords used in the language .
407+ // Edition-specific keywords that are used in stable Rust .
408408 ( 51 , Dyn , "dyn" ) // >= 2018 Edition only
409409
410- // Edition-specific keywords reserved for future use.
410+ // Edition-specific keywords that are used in unstable Rust or reserved for future use.
411411 ( 52 , Async , "async" ) // >= 2018 Edition only
412412 ( 53 , Try , "try" ) // >= 2018 Edition only
413413
You can’t perform that action at this time.
0 commit comments