Skip to content
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

Fix regression 61475 #61500

Merged
merged 2 commits into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 11 additions & 7 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,10 +628,10 @@ impl<'a> Parser<'a> {
}
_ => {
Err(if self.prev_token_kind == PrevTokenKind::DocComment {
self.span_fatal_err(self.prev_span, Error::UselessDocComment)
} else {
self.expected_ident_found()
})
self.span_fatal_err(self.prev_span, Error::UselessDocComment)
} else {
self.expected_ident_found()
})
}
}
}
Expand Down Expand Up @@ -1660,8 +1660,8 @@ impl<'a> Parser<'a> {
path = self.parse_path(PathStyle::Type)?;
path_span = path_lo.to(self.prev_span);
} else {
path = ast::Path { segments: Vec::new(), span: DUMMY_SP };
path_span = self.span.to(self.span);
path = ast::Path { segments: Vec::new(), span: path_span };
}

// See doc comment for `unmatched_angle_bracket_count`.
Expand Down Expand Up @@ -2847,7 +2847,11 @@ impl<'a> Parser<'a> {
// want to keep their span info to improve diagnostics in these cases in a later stage.
(true, Some(AssocOp::Multiply)) | // `{ 42 } *foo = bar;` or `{ 42 } * 3`
(true, Some(AssocOp::Subtract)) | // `{ 42 } -5`
Comment on lines 2848 to 2849
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are included, why isn't { 42 } & 3? Surely the have the same property?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah this seems like a reporting-only heuristic and only the can_continue_expr_unambiguously check is relevant to what I was seeing.

(true, Some(AssocOp::Add)) => { // `{ 42 } + 42
(true, Some(AssocOp::LAnd)) | // `{ 42 } &&x` (#61475)
(true, Some(AssocOp::Add)) // `{ 42 } + 42
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Add case (although not introduced in this PR) is also a bit strange... surely Rust expressions can't start with +?
That is, Rust has no "unary plus" operator, like other languages do.

// If the next token is a keyword, then the tokens above *are* unambiguously incorrect:
// `if x { a } else { b } && if y { c } else { d }`
if !self.look_ahead(1, |t| t.is_reserved_ident()) => {
Comment on lines +2852 to +2854
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the intention here to catch if, match, loop, while and for? Because it also triggers for {} &&false (which would otherwise parse the same way as {} & &false), despite {} &&0 being unaffected.

Copy link
Member

@eddyb eddyb Jul 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this seems coincidental to #74233, and not actually a bug in itself.

// These cases are ambiguous and can't be identified in the parser alone
let sp = self.sess.source_map().start_point(self.span);
self.sess.ambiguous_block_expr_parse.borrow_mut().insert(sp, lhs.span);
Expand Down Expand Up @@ -5298,7 +5302,7 @@ impl<'a> Parser<'a> {
let mut where_clause = WhereClause {
id: ast::DUMMY_NODE_ID,
predicates: Vec::new(),
span: DUMMY_SP,
span: self.prev_span.to(self.prev_span),
};

if !self.eat_keyword(kw::Where) {
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/issues/issue-61475.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// run-pass
#![allow(dead_code)]

enum E {
A, B
}

fn main() {
match &&E::A {
&&E::A => {
}
&&E::B => {
}
};
}