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

Lower the precedence of the as operator. #1951

Merged
merged 2 commits into from
Oct 8, 2019
Merged

Conversation

goffrie
Copy link
Contributor

@goffrie goffrie commented Oct 3, 2019

Previously, the as operator was being parsed like a postfix expression, and
therefore being given the highest possible precedence. That caused it to bind
more tightly than prefix operators, which it should not. Instead, parse it
somewhat like a normal binary expression with some special-casing.

Fixes #1851.

Previously, the `as` operator was being parsed like a postfix expression, and
therefore being given the highest possible precedence. That caused it to bind
more tightly than prefix operators, which it should not. Instead, parse it
somewhat like a normal binary expression with some special-casing.
Copy link
Member

@matklad matklad left a comment

Choose a reason for hiding this comment

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

❤️

@@ -296,6 +301,7 @@ fn lhs(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)>
// fn foo() {
// let _ = &1;
// let _ = &mut &f();
// let _ = &1 as *const i32;
Copy link
Member

Choose a reason for hiding this comment

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

Let's move this test to the if p.at(T![as]) { line

// *&1 as u64;
// *x(1);
// &x[1];
// -1..2;
Copy link
Member

Choose a reason for hiding this comment

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

Let's move these additional cases to an out-of-line test somewhere in test-data/parser/ok. The purpose of the inline tests is not to exhaustively check everything, but to explain what the code immediately after them does, and, for that purposes, simple cases are more useful.

@goffrie
Copy link
Contributor Author

goffrie commented Oct 5, 2019

Done :)

@matklad
Copy link
Member

matklad commented Oct 8, 2019

bors r+

Thanks!

bors bot added a commit that referenced this pull request Oct 8, 2019
1951: Lower the precedence of the `as` operator. r=matklad a=goffrie

Previously, the `as` operator was being parsed like a postfix expression, and
therefore being given the highest possible precedence. That caused it to bind
more tightly than prefix operators, which it should not. Instead, parse it
somewhat like a normal binary expression with some special-casing.

Fixes #1851.

Co-authored-by: Geoffry Song <goffrie@gmail.com>
@bors
Copy link
Contributor

bors bot commented Oct 8, 2019

Build succeeded

@bors bors bot merged commit b4fe06b into rust-lang:master Oct 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong precedence between as and &[mut]
2 participants