diff options
| author | bors <bors@rust-lang.org> | 2017-11-21 12:32:59 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-11-21 12:32:59 +0000 |
| commit | f28df200260c89b2a0bdf942510e0f888c29a70d (patch) | |
| tree | 731a918787dcc36a4ce994d5a79626d59b61ee13 /src/libsyntax/parse/parser.rs | |
| parent | ebda7662dbb79ab0a9feb79d367d0818c23ff1dc (diff) | |
| parent | 90f5cfdfbd3c9e39f897fd2271c7b1c7fdaae58e (diff) | |
| download | rust-f28df200260c89b2a0bdf942510e0f888c29a70d.tar.gz rust-f28df200260c89b2a0bdf942510e0f888c29a70d.zip | |
Auto merge of #45771 - petrochenkov:crate, r=nikomatsakis
Support `::crate` in paths cc https://github.com/rust-lang/rust/issues/45477 Fixes https://github.com/rust-lang/rust/issues/45229
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c1819307928..0b03429ea2e 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3916,6 +3916,10 @@ impl<'a> Parser<'a> { self.look_ahead(1, |t| t.is_ident() && !t.is_reserved_ident()) } + fn is_crate_vis(&self) -> bool { + self.token.is_keyword(keywords::Crate) && self.look_ahead(1, |t| t != &token::ModSep) + } + fn eat_auto_trait(&mut self) -> bool { if self.token.is_keyword(keywords::Auto) && self.look_ahead(1, |t| t.is_keyword(keywords::Trait)) @@ -4026,10 +4030,15 @@ impl<'a> Parser<'a> { node: StmtKind::Item(macro_def), span: lo.to(self.prev_span), } - // Starts like a simple path, but not a union item. + // Starts like a simple path, but not a union item or item with `crate` visibility. + // Our goal here is to parse an arbitrary path `a::b::c` but not something that starts + // like a path (1 token), but it fact not a path. + // `union::b::c` - path, `union U { ... }` - not a path. + // `crate::b::c` - path, `crate struct S;` - not a path. } else if self.token.is_path_start() && !self.token.is_qpath_start() && - !self.is_union_item() { + !self.is_union_item() && + !self.is_crate_vis() { let pth = self.parse_path(PathStyle::Expr)?; if !self.eat(&token::Not) { @@ -5399,7 +5408,9 @@ impl<'a> Parser<'a> { pub fn parse_visibility(&mut self, can_take_tuple: bool) -> PResult<'a, Visibility> { maybe_whole!(self, NtVis, |x| x); - if self.eat_keyword(keywords::Crate) { + self.expected_tokens.push(TokenType::Keyword(keywords::Crate)); + if self.is_crate_vis() { + self.bump(); // `crate` return Ok(Visibility::Crate(self.prev_span, CrateSugar::JustCrate)); } |
