diff options
| author | bors <bors@rust-lang.org> | 2018-03-17 23:22:57 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-03-17 23:22:57 +0000 |
| commit | ca6a98426192f838cc90a18709f92d425b86029e (patch) | |
| tree | aad9717ff8dca9636794c782148b0729b46090e0 /src/libsyntax/parse/lexer | |
| parent | adf2135adc4a65a78ba053f04c29d7fe0468eb87 (diff) | |
| parent | ed5ea5c705ccea7d2eef1558530e87d2dbb88be7 (diff) | |
| download | rust-ca6a98426192f838cc90a18709f92d425b86029e.tar.gz rust-ca6a98426192f838cc90a18709f92d425b86029e.zip | |
Auto merge of #48842 - petrochenkov:under, r=nikomatsakis
syntax: Make `_` a reserved identifier
Why:
- Lexically `_` is an identifier.
- Internally it makes implementation of `use Trait as _;` (https://github.com/rust-lang/rust/issues/48216) and some other things cleaner.
- We prevent the externally observable effect of `_` being accepted by macros expecting `ident` by treating `_` specially in the `ident` matcher:
```rust
macro_rules! m {
($i: ident) => { let $i = 10; }
}
m!(_); // Still an error
```
Diffstat (limited to 'src/libsyntax/parse/lexer')
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 815ba49a60a..9d1bfba7b94 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -34,7 +34,7 @@ pub struct TokenAndSpan { impl Default for TokenAndSpan { fn default() -> Self { - TokenAndSpan { tok: token::Underscore, sp: syntax_pos::DUMMY_SP } + TokenAndSpan { tok: token::Whitespace, sp: syntax_pos::DUMMY_SP } } } @@ -126,7 +126,7 @@ impl<'a> StringReader<'a> { pub fn try_next_token(&mut self) -> Result<TokenAndSpan, ()> { assert!(self.fatal_errs.is_empty()); let ret_val = TokenAndSpan { - tok: replace(&mut self.peek_tok, token::Underscore), + tok: replace(&mut self.peek_tok, token::Whitespace), sp: self.peek_span, }; self.advance_token()?; @@ -1133,14 +1133,8 @@ impl<'a> StringReader<'a> { self.bump(); } - return Ok(self.with_str_from(start, |string| { - if string == "_" { - token::Underscore - } else { - // FIXME: perform NFKC normalization here. (Issue #2253) - token::Ident(self.mk_ident(string)) - } - })); + // FIXME: perform NFKC normalization here. (Issue #2253) + return Ok(self.with_str_from(start, |string| token::Ident(self.mk_ident(string)))); } if is_dec_digit(c) { |
