File tree 4 files changed +14
-27
lines changed
4 files changed +14
-27
lines changed Original file line number Diff line number Diff line change @@ -105,17 +105,6 @@ impl Path {
105
105
}
106
106
}
107
107
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
-
119
108
pub fn is_global ( & self ) -> bool {
120
109
!self . segments . is_empty ( ) && self . segments [ 0 ] . ident . name == keywords:: PathRoot . name ( )
121
110
}
@@ -144,7 +133,7 @@ impl PathSegment {
144
133
pub fn from_ident ( ident : Ident ) -> Self {
145
134
PathSegment { ident, id : DUMMY_NODE_ID , args : None }
146
135
}
147
- pub fn crate_root ( span : Span ) -> Self {
136
+ pub fn path_root ( span : Span ) -> Self {
148
137
PathSegment :: from_ident ( Ident :: new ( keywords:: PathRoot . name ( ) , span) )
149
138
}
150
139
}
Original file line number Diff line number Diff line change @@ -318,9 +318,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
318
318
args : Vec < ast:: GenericArg > ,
319
319
bindings : Vec < ast:: TypeBinding > )
320
320
-> 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
+ }
321
327
let last_ident = idents. pop ( ) . unwrap ( ) ;
322
- let mut segments: Vec < ast:: PathSegment > = vec ! [ ] ;
323
-
324
328
segments. extend ( idents. into_iter ( ) . map ( |ident| {
325
329
ast:: PathSegment :: from_ident ( ident. with_span_pos ( span) )
326
330
} ) ) ;
@@ -334,13 +338,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
334
338
id : ast:: DUMMY_NODE_ID ,
335
339
args,
336
340
} ) ;
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 }
344
342
}
345
343
346
344
/// Constructs a qualified path.
Original file line number Diff line number Diff line change @@ -2082,7 +2082,7 @@ impl<'a> Parser<'a> {
2082
2082
let mut segments = Vec :: new ( ) ;
2083
2083
let mod_sep_ctxt = self . span . ctxt ( ) ;
2084
2084
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) ) ) ;
2086
2086
}
2087
2087
self . parse_path_segments ( & mut segments, style, enable_warning) ?;
2088
2088
@@ -7685,7 +7685,7 @@ impl<'a> Parser<'a> {
7685
7685
let mod_sep_ctxt = self . span . ctxt ( ) ;
7686
7686
if self . eat ( & token:: ModSep ) {
7687
7687
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) )
7689
7689
) ;
7690
7690
}
7691
7691
Original file line number Diff line number Diff line change @@ -353,7 +353,7 @@ declare_keywords! {
353
353
( 2 , DollarCrate , "$crate" )
354
354
( 3 , Underscore , "_" )
355
355
356
- // Keywords used in the language .
356
+ // Keywords that are used in stable Rust .
357
357
( 4 , As , "as" )
358
358
( 5 , Box , "box" )
359
359
( 6 , Break , "break" )
@@ -391,7 +391,7 @@ declare_keywords! {
391
391
( 38 , Where , "where" )
392
392
( 39 , While , "while" )
393
393
394
- // Keywords reserved for future use.
394
+ // Keywords that are used in unstable Rust or reserved for future use.
395
395
( 40 , Abstract , "abstract" )
396
396
( 41 , Become , "become" )
397
397
( 42 , Do , "do" )
@@ -404,10 +404,10 @@ declare_keywords! {
404
404
( 49 , Virtual , "virtual" )
405
405
( 50 , Yield , "yield" )
406
406
407
- // Edition-specific keywords used in the language .
407
+ // Edition-specific keywords that are used in stable Rust .
408
408
( 51 , Dyn , "dyn" ) // >= 2018 Edition only
409
409
410
- // Edition-specific keywords reserved for future use.
410
+ // Edition-specific keywords that are used in unstable Rust or reserved for future use.
411
411
( 52 , Async , "async" ) // >= 2018 Edition only
412
412
( 53 , Try , "try" ) // >= 2018 Edition only
413
413
You can’t perform that action at this time.
0 commit comments