Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Dec 3, 2018
1 parent d415844 commit d08f7dc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 27 deletions.
13 changes: 1 addition & 12 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,6 @@ impl Path {
}
}

// Make a "crate root" segment for this path unless it already has it
// or starts with something like `self`/`super`/`$crate`/etc.
pub fn make_root(&self) -> Option<PathSegment> {
if let Some(ident) = self.segments.get(0).map(|seg| seg.ident) {
if ident.is_path_segment_keyword() {
return None;
}
}
Some(PathSegment::crate_root(self.span.shrink_to_lo()))
}

pub fn is_global(&self) -> bool {
!self.segments.is_empty() && self.segments[0].ident.name == keywords::PathRoot.name()
}
Expand Down Expand Up @@ -144,7 +133,7 @@ impl PathSegment {
pub fn from_ident(ident: Ident) -> Self {
PathSegment { ident, id: DUMMY_NODE_ID, args: None }
}
pub fn crate_root(span: Span) -> Self {
pub fn path_root(span: Span) -> Self {
PathSegment::from_ident(Ident::new(keywords::PathRoot.name(), span))
}
}
Expand Down
16 changes: 7 additions & 9 deletions src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
args: Vec<ast::GenericArg>,
bindings: Vec<ast::TypeBinding> )
-> ast::Path {
assert!(!idents.is_empty());
let add_root = global && !idents[0].is_path_segment_keyword();
let mut segments = Vec::with_capacity(idents.len() + add_root as usize);
if add_root {
segments.push(ast::PathSegment::path_root(span));
}
let last_ident = idents.pop().unwrap();
let mut segments: Vec<ast::PathSegment> = vec![];

segments.extend(idents.into_iter().map(|ident| {
ast::PathSegment::from_ident(ident.with_span_pos(span))
}));
Expand All @@ -334,13 +338,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
id: ast::DUMMY_NODE_ID,
args,
});
let mut path = ast::Path { span, segments };
if global {
if let Some(seg) = path.make_root() {
path.segments.insert(0, seg);
}
}
path
ast::Path { span, segments }
}

/// Constructs a qualified path.
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2082,7 +2082,7 @@ impl<'a> Parser<'a> {
let mut segments = Vec::new();
let mod_sep_ctxt = self.span.ctxt();
if self.eat(&token::ModSep) {
segments.push(PathSegment::crate_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt)));
segments.push(PathSegment::path_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt)));
}
self.parse_path_segments(&mut segments, style, enable_warning)?;

Expand Down Expand Up @@ -7685,7 +7685,7 @@ impl<'a> Parser<'a> {
let mod_sep_ctxt = self.span.ctxt();
if self.eat(&token::ModSep) {
prefix.segments.push(
PathSegment::crate_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt))
PathSegment::path_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt))
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/libsyntax_pos/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ declare_keywords! {
(2, DollarCrate, "$crate")
(3, Underscore, "_")

// Keywords used in the language.
// Keywords that are used in stable Rust.
(4, As, "as")
(5, Box, "box")
(6, Break, "break")
Expand Down Expand Up @@ -391,7 +391,7 @@ declare_keywords! {
(38, Where, "where")
(39, While, "while")

// Keywords reserved for future use.
// Keywords that are used in unstable Rust or reserved for future use.
(40, Abstract, "abstract")
(41, Become, "become")
(42, Do, "do")
Expand All @@ -404,10 +404,10 @@ declare_keywords! {
(49, Virtual, "virtual")
(50, Yield, "yield")

// Edition-specific keywords used in the language.
// Edition-specific keywords that are used in stable Rust.
(51, Dyn, "dyn") // >= 2018 Edition only

// Edition-specific keywords reserved for future use.
// Edition-specific keywords that are used in unstable Rust or reserved for future use.
(52, Async, "async") // >= 2018 Edition only
(53, Try, "try") // >= 2018 Edition only

Expand Down

0 comments on commit d08f7dc

Please sign in to comment.