-
Notifications
You must be signed in to change notification settings - Fork 13k
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
suggest parenthesis around ExprWithBlock BinOp ExprWithBlock #105223
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
err.span_suggestion_short( | ||
span.shrink_to_hi(), | ||
"consider using a semicolon here", | ||
";", | ||
Applicability::MachineApplicable, | ||
Applicability::MaybeIncorrect, |
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.
This was already wrong on nightly and isn't caused by this PR.
Is this a temporary fix? Shouldn’t I was expecting
to be valid Rust and equals to |
This is an unfortunate side effect of the current Rust grammar. When a statement starts with an ExpressionWithBlock (such as a Changing this will probably require an RFC and a nontrivial amount of work, since this would introduce parsing ambiguities based on types, for example: fn foo() -> impl FnOnce() -> bool {
match () { () => () }
|| match () { () => true } // closure
}
fn bar() -> bool {
// (match () { () => true }) || match () { () => true } // logical or
match () { () => true } || match () { () => true } // logical or
}
fn baz() -> &'static &'static bool {
match () { () => () }
&&match () { () => true } // reference to reference
}
fn quux() -> bool {
// (match () { () => true }) && match () { () => true } // logical and
match () { () => true } && match () { () => true } // logical and
} Furthermore, this would break resolution of unary vs binary use std::ops;
struct Bar;
impl ops::Neg for Bar {
type Output = ();
fn neg(self) {
println!("neg");
}
}
impl ops::Sub<Bar> for () {
type Output = ();
fn sub(self, _: Bar) {
println!("sub");
}
}
fn main() {
{
match () {
() => (),
} - match () {
() => Bar,
}
}
{
(match () {
() => (),
}) - match () {
() => Bar,
}
}
} |
@bors r+ |
1 similar comment
@bors r+ |
…ochenkov suggest parenthesis around ExprWithBlock BinOp ExprWithBlock fix rust-lang#105179 fix rust-lang#102171
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#104912 (PartialEq: PERs are homogeneous) - rust-lang#104952 (Streamline the user experience for `x.py setup`) - rust-lang#104953 (Ensure required submodules at the same time as updating existing submodules) - rust-lang#105180 (Use proper HirId for async track_caller attribute check) - rust-lang#105222 (std update libc version and freebsd image build dependencies) - rust-lang#105223 (suggest parenthesis around ExprWithBlock BinOp ExprWithBlock) - rust-lang#105230 (Skip recording resolution for duplicated generic params.) - rust-lang#105301 (update Miri) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Basically, this would require to have significant newline to distinguish them. Or to require a |
1 similar comment
Basically, this would require to have significant newline to distinguish them. Or to require a |
…ochenkov suggest parenthesis around ExprWithBlock BinOp ExprWithBlock fix rust-lang#105179 fix rust-lang#102171
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#104912 (PartialEq: PERs are homogeneous) - rust-lang#104952 (Streamline the user experience for `x.py setup`) - rust-lang#104953 (Ensure required submodules at the same time as updating existing submodules) - rust-lang#105180 (Use proper HirId for async track_caller attribute check) - rust-lang#105222 (std update libc version and freebsd image build dependencies) - rust-lang#105223 (suggest parenthesis around ExprWithBlock BinOp ExprWithBlock) - rust-lang#105230 (Skip recording resolution for duplicated generic params.) - rust-lang#105301 (update Miri) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
fix #105179
fix #102171