-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Propagate restrictions against struct literals to the RHS of assignment #17290
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
Conversation
RESTRICT_NO_STRUCT_LITERAL | ||
} else { | ||
UNRESTRICTED | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would probably be cleaner code to give the enum variants here int values and treat them like flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the RESTRICT_NO_BAR_OR_DOUBLEBAR_OP
variant, it seems like a reasonable way to refactor, but it might be better as a separate PR.
2adc5c8
to
b04a566
Compare
New version force-pushed, now with more bitflags. |
static Unrestricted = 0b0000, | ||
static ResStmtExpr = 0b0001, | ||
static ResNoBarOp = 0b0010, | ||
static ResNoDoubleBarOp = 0b0100, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please spell out Restrict
for the flags and don't lose the BarOr
from this one - longer names ftw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Losing BarOr
was intentional, as it can just set both flags to indicate it doesn't want either.
Although, looking at it now, it doesn't actually seem to be set anywhere in the parser. I guess I'll just drop it.
Nice, thanks for the bitflags conversion! r=me with the changes requested. |
This makes having multiple restrictions at once cleaner. Also drop NO_DOUBLEBAR restriction since it is never used.
This prevents confusing errors when accidentally using an assignment in an `if` expression. For example: ```rust fn main() { let x = 1u; if x = x { println!("{}", x); } } ``` Previously, this yielded: ``` test.rs:4:16: 4:17 error: expected `:`, found `!` test.rs:4 println!("{}", x); ^ ``` With this change, it now yields: ``` test.rs:3:8: 3:13 error: mismatched types: expected `bool`, found `()` (expected bool, found ()) test.rs:3 if x = x { ^~~~~ ``` Closes issue rust-lang#17283
b04a566
to
0e230c0
Compare
This prevents confusing errors when accidentally using an assignment in an
if
expression. For example:Previously, this yielded:
With this change, it now yields:
Closes issue #17283
r? @nick29581