Skip to content

parser: Remove Deref impl from Parser #61616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
parser: Remove look_ahead_span
  • Loading branch information
petrochenkov committed Jun 7, 2019
commit 3dbee57daee312ee073006101053f5e3934de7c6
9 changes: 4 additions & 5 deletions src/libsyntax/parse/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,13 @@ impl<'a> Parser<'a> {
let mut recovered = None;
if self.token == token::Dot {
// Attempt to recover `.4` as `0.4`.
recovered = self.look_ahead(1, |t| {
recovered = self.look_ahead(1, |next_token| {
if let token::Literal(token::Lit { kind: token::Integer, symbol, suffix })
= t.kind {
let next_span = self.look_ahead_span(1);
if self.token.span.hi() == next_span.lo() {
= next_token.kind {
if self.token.span.hi() == next_token.span.lo() {
let s = String::from("0.") + &symbol.as_str();
let kind = TokenKind::lit(token::Float, Symbol::intern(&s), suffix);
return Some(Token::new(kind, self.token.span.to(next_span)));
return Some(Token::new(kind, self.token.span.to(next_token.span)));
}
}
None
Expand Down
14 changes: 1 addition & 13 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,18 +1064,6 @@ impl<'a> Parser<'a> {
})
}

crate fn look_ahead_span(&self, dist: usize) -> Span {
if dist == 0 {
return self.token.span
}

match self.token_cursor.frame.tree_cursor.look_ahead(dist - 1) {
Some(TokenTree::Token(token)) => token.span,
Some(TokenTree::Delimited(span, ..)) => span.entire(),
None => self.look_ahead_span(dist - 1),
}
}

/// Returns whether any of the given keywords are `dist` tokens ahead of the current one.
fn is_keyword_ahead(&self, dist: usize, kws: &[Symbol]) -> bool {
self.look_ahead(dist, |t| kws.iter().any(|&kw| t.is_keyword(kw)))
Expand Down Expand Up @@ -3067,7 +3055,7 @@ impl<'a> Parser<'a> {
let mut err =
self.sess.span_diagnostic.struct_span_err(self.token.span, &msg);
let span_after_type = parser_snapshot_after_type.token.span;
err.span_label(self.look_ahead_span(1).to(span_after_type),
err.span_label(self.look_ahead(1, |t| t.span).to(span_after_type),
"interpreted as generic arguments");
err.span_label(self.token.span, format!("not interpreted as {}", op_noun));

Expand Down