Closed
Description
Currently if || S {} {}
is parsed as if (|| S {}) {}
. I think it should be parsed as if (|| S) {} {}
, to be consistent with handling of other similar "open" binary and prefix expressions (lambdas can be viewed as a form of a prefix expression).
Consider these expressions:
fn main() {
if -S {};
if 0 == -S {};
if 0 == S {};
if || S {} {};
if 0 == || S {} {};
}
They are parsed as
fn main() {
if (-S) {};
if (0 == -S) {};
if (0 == S) {};
if (|| S {}) {};
if (0 == || S {}) {};
}
The last two cases seem to be different from others and wrong. @eddyb on IRC suggested that this behavior could have been introduced accidentally during transition from lambdas with blocks as bodies to lambdas with arbitrary expressions as bodies.
If this is a bug, fixing it can render some previously valid programs invalid, but this seems rater unlikely, as bare lambdas rarely end up in conditionals. It is possible though:
struct S {}
struct E;
impl<T> PartialEq<T> for E {
fn eq(&self, _: &T) -> bool { true }
}
fn main() {
if E == || S {} {}
}