You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python allows chaining comparison operators as a helpful shorthand:
ifa<b<c: # equivalent to (a < b and b < c)
...
However Rust explicitly disallows this:
fnmain(){5 < 10 < 15}// error: comparison operators cannot be chained// --> chain.rs:2:5// |// 2 | 5 < 10 < 15// | ^ ^// |// help: split the comparison into two// |// 2 | 5 < 10 && 10 < 15// | ^^^^^//// error: aborting due to previous error
rust-lang/rfcs#558 seems to be the source of this explicit disallow, with the primary motivation being confusing behavior: a < b < c used to be interpreted as (a < b) < c, resulting in a type error. The RFC also claims this would allow implentation of Python-like chained comparison operators in the future. Is there any motivation not to add these Python-like chained comparison operators into Rust? Given that the syntax for it has been a compiler error since pre-1.0, it doesn't seem like it could be a breaking change. Thoughts?
The text was updated successfully, but these errors were encountered:
Hi! Additions or changes to the language need to go through our RFC process. Before an RFC is written, the feature can also be discussed in our internals forum to find other people interested in it.
The internals forum does sound like a better place for this. Thanks for the tip!
(As an aside, I didn't find anything suggesting the internals forum while I was looking into opening this issue. Perhaps there's room for better documentation pointing there?)
Python allows chaining comparison operators as a helpful shorthand:
However Rust explicitly disallows this:
rust-lang/rfcs#558 seems to be the source of this explicit disallow, with the primary motivation being confusing behavior:
a < b < c
used to be interpreted as(a < b) < c
, resulting in a type error. The RFC also claims this would allow implentation of Python-like chained comparison operators in the future. Is there any motivation not to add these Python-like chained comparison operators into Rust? Given that the syntax for it has been a compiler error since pre-1.0, it doesn't seem like it could be a breaking change. Thoughts?The text was updated successfully, but these errors were encountered: