diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-28 17:17:26 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-28 17:17:26 +0100 |
| commit | 3828fa2852bf5e622267b24c4eda74e4fa6cb5f9 (patch) | |
| tree | 942eb14f5b56c674c718599132032347e61c4d04 /src/librustc_parse/parser/item.rs | |
| parent | 76fe44928281ae6f1ffe881712e02fb2358a4883 (diff) | |
| parent | b2605c118de31db9d61a9f7d0d158b9bf35f7a4a (diff) | |
Rollup merge of #69384 - petrochenkov:nounnorm, r=Centril
parser: `token` -> `normalized_token`, `nonnormalized_token` -> `token` So, after https://github.com/rust-lang/rust/pull/69006, its follow-ups and an attempt to remove `Parser::prev_span` I came to the conclusion that the unnormalized token and its span is what you want in most cases, so it should be default. Normalization only makes difference in few cases where we are checking against `token::Ident` or `token::Lifetime` specifically. This PR uses `normalized_token` for those cases. Using normalization explicitly means that people writing code should remember about `NtIdent` and `NtLifetime` in general. (That is alleviated by the fact that `token.ident()` and `fn parse_ident_*` are already written.) Remembering about `NtIdent`, was, however, already the case, kind of, because the implicit normalization was performed only for the current/previous token, but not for things like `look_ahead`. As a result, most of token classification methods in `token.rs` already take `NtIdent` into account (this PR fixes a few pre-existing minor mistakes though). The next step is removing `normalized(_prev)_token` entirely and replacing it with `token.ident()` (mostly) and `token.normalize()` (occasionally). I want to make it a separate PR for that and run it though perf. `normalized_token` filled on every bump has both a potential to avoid repeated normalization, and to do unnecessary work in advance (it probably doesn't matter anyway, the normalization is very cheap). r? @Centril
Diffstat (limited to 'src/librustc_parse/parser/item.rs')
| -rw-r--r-- | src/librustc_parse/parser/item.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index d7d6fcd05b7..ef4246609da 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -741,11 +741,10 @@ impl<'a> Parser<'a> { } fn parse_ident_or_underscore(&mut self) -> PResult<'a, ast::Ident> { - match self.token.kind { + match self.normalized_token.kind { token::Ident(name @ kw::Underscore, false) => { - let span = self.token.span; self.bump(); - Ok(Ident::new(name, span)) + Ok(Ident::new(name, self.normalized_prev_token.span)) } _ => self.parse_ident(), } @@ -1537,7 +1536,7 @@ impl<'a> Parser<'a> { let is_name_required = match self.token.kind { token::DotDotDot => false, - _ => req_name(&self.token), + _ => req_name(&self.normalized_token), }; let (pat, ty) = if is_name_required || self.is_named_param() { debug!("parse_param_general parse_pat (is_name_required:{})", is_name_required); @@ -1603,12 +1602,11 @@ impl<'a> Parser<'a> { fn parse_self_param(&mut self) -> PResult<'a, Option<Param>> { // Extract an identifier *after* having confirmed that the token is one. let expect_self_ident = |this: &mut Self| { - match this.token.kind { + match this.normalized_token.kind { // Preserve hygienic context. token::Ident(name, _) => { - let span = this.token.span; this.bump(); - Ident::new(name, span) + Ident::new(name, this.normalized_prev_token.span) } _ => unreachable!(), } @@ -1645,7 +1643,7 @@ impl<'a> Parser<'a> { // Only a limited set of initial token sequences is considered `self` parameters; anything // else is parsed as a normal function parameter list, so some lookahead is required. let eself_lo = self.token.span; - let (eself, eself_ident, eself_hi) = match self.token.kind { + let (eself, eself_ident, eself_hi) = match self.normalized_token.kind { token::BinOp(token::And) => { let eself = if is_isolated_self(self, 1) { // `&self` |
