Skip to content

Commit

Permalink
parser: Remove Parser::prev_span
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Feb 29, 2020
1 parent d0ba438 commit 7de9a72
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/librustc_parse/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ impl<'a> Parser<'a> {
if self.normalized_token.span.rust_2018() { self.parse_asyncness() } else { Async::No };
if asyncness.is_async() {
// Feature-gate `async ||` closures.
self.sess.gated_spans.gate(sym::async_closure, self.prev_span);
self.sess.gated_spans.gate(sym::async_closure, self.normalized_prev_token.span);
}

let capture_clause = self.parse_capture_clause();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_parse/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ impl<'a> Parser<'a> {
&& self.look_ahead(1, |t| t.is_non_raw_ident_where(|i| i.name != kw::As))
{
self.bump(); // `default`
Defaultness::Default(self.prev_span)
Defaultness::Default(self.normalized_prev_token.span)
} else {
Defaultness::Final
}
Expand Down
18 changes: 10 additions & 8 deletions src/librustc_parse/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ pub struct Parser<'a> {
/// Use this if you need to check for `token::Ident` or `token::Lifetime` specifically,
/// this also includes edition checks for edition-specific keyword identifiers.
pub normalized_prev_token: Token,
/// FIXME: Remove in favor of the equivalent `prev_token.span`.
pub prev_span: Span,
restrictions: Restrictions,
/// Used to determine the path to externally loaded source files.
pub(super) directory: Directory,
Expand Down Expand Up @@ -377,7 +375,6 @@ impl<'a> Parser<'a> {
normalized_token: Token::dummy(),
prev_token: Token::dummy(),
normalized_prev_token: Token::dummy(),
prev_span: DUMMY_SP,
restrictions: Restrictions::empty(),
recurse_into_file_modules,
directory: Directory {
Expand Down Expand Up @@ -848,9 +845,6 @@ impl<'a> Parser<'a> {
self.normalized_prev_token = self.normalized_token.take();
self.set_token(next_token);

// Update fields derived from the previous token.
self.prev_span = self.prev_token.span;

// Diagnostics.
self.expected_tokens.clear();
}
Expand Down Expand Up @@ -897,12 +891,20 @@ impl<'a> Parser<'a> {

/// Parses unsafety: `unsafe` or nothing.
fn parse_unsafety(&mut self) -> Unsafe {
if self.eat_keyword(kw::Unsafe) { Unsafe::Yes(self.prev_span) } else { Unsafe::No }
if self.eat_keyword(kw::Unsafe) {
Unsafe::Yes(self.normalized_prev_token.span)
} else {
Unsafe::No
}
}

/// Parses constness: `const` or nothing.
fn parse_constness(&mut self) -> Const {
if self.eat_keyword(kw::Const) { Const::Yes(self.prev_span) } else { Const::No }
if self.eat_keyword(kw::Const) {
Const::Yes(self.normalized_prev_token.span)
} else {
Const::No
}
}

/// Parses mutability (`mut` or nothing).
Expand Down

0 comments on commit 7de9a72

Please sign in to comment.