-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Implement the illegal_floating_point_literal_pattern compat lint #41293
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
☔ The latest upstream changes (presumably #41294) made this pull request unmergeable. Please resolve the merge conflicts. |
6ec00d2
to
0e33daa
Compare
I'll spin up a crater run. Thanks @est31! |
src/librustc_const_eval/pattern.rs
Outdated
format!("floating point constants cannot be used in patterns")); | ||
} | ||
_ => {} | ||
} | ||
match const_cx.eval(expr) { |
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 branch may be dead now.
src/test/run-pass/issue-7222.rs
Outdated
|
||
match 0.0 { | ||
0.0 ... FOO => (), | ||
0.0 ... FOOFL => (), |
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, i feel, should keep working just fine. It is just a range and testing that floats fall into some range is encouraged even.
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.
I'm neutral about ranges, will adopt whatever the consensus is.
@@ -29,7 +29,7 @@ fn is_zero(v: Value) -> bool { | |||
unsafe { | |||
match v { | |||
Value { tag: Tag::I, u: U { i: 0 } } => true, | |||
Value { tag: Tag::F, u: U { f: 0.0 } } => true, | |||
Value { tag: Tag::F, u: U { u: 0 } } => true, |
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.
Similarly here. This code is already annotated with unsafe and all.
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.
Although i guess one could argue that people should just match on the bit pattern (i.e. The integer variant)
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 is annotated with unsafe, but unsafe doesn't allow everything, so IMO its okay to disallow it. Especially as making unsafe feel more comfortable to write than non unsafe code is not really a priority of Rust.
Crater report: https://gist.github.com/nikomatsakis/b482d33f058a8dbccc6a0def6545ed7f
But the |
I count 15 legit regressions out of the 35. Those are: |
272fb0a
to
14c1608
Compare
@leodasvacas thanks for that! The majority, then, are "equality" matches, right? |
i.e., as opposed to |
cc @rust-lang/lang -- note that @est31 has kindly quantified the breakage here. I'm not sure how I feel about this. In some ways, I'd like to permit matches over floating points, which clearly have some utility, but definitely it raises some thorny questions (e.g., matching on Still, I kind of feel like maybe we should carve out special-case rules here around floats and deal with it, even if that introduces a measure of inconsistency. I guess we have to think about how this may interact with constant evaluation in general. |
@nikomatsakis Yes, I think only geodate and rand used ranges. |
Just throwing out that this will also regress ayzim which matches on |
The crater was run and the results posted, so removing the needs-crater tag. |
Nominating for discussion in team meeting. |
@est31 after some discussion in the @rust-lang/lang meeting, I think we decided we'd like to start issuing warnings (not deny-by-default) for this case. For that, we'll need a separate tracking issue etc. Do you think you can update this PR to do that? |
14c1608
to
e5f21bc
Compare
It seems like we should have the same rules for now (no floats) and if its a problem we can expedite finding a permanent solution. Imagining that we allow float consts in ranges, if we use PartialOrd NaN doesn't fall into These can all be transformed to conditionals right? Not saying its nice but it does work. |
Yes. The main question is, is there any reason that this is bad? (I don't see one.) |
just that float equality is a foot gun. I don't really have a strong opinion about what we do here. I guess procedurally I'm a bit worried we are capriciously reversing course on an RFC. |
Well, I don't think the RFC addressed range literals at all. The focus was purely on equality and nobody brought up (The RFC also reported 6 regressions, because it was based on flawed data, since literals were accidentally overlooked.) (My view is that in such cases, procedurally, the @rust-lang/lang team can make minor adjustments, within the spirit of the original consensus. If you don't feel this is such a case, I'd not necessarily be opposed to issuing the warnings, and perhaps opening another RFC to explicitly allow |
A misguided user might also forget to handle NaN and write something like: match x {
0.0 ... INF => { ... }
NEG_INF ... 0.0 => { ... }
_ => unreachable!()
} Of course depending on the context panicking might be better than whatever would happen if they instead wrote this conditional: if x >= 0.0 { ... }
else { ... } |
@nikomatsakis I guess one thing I do feel kind of strongly about is that we have the same policy for floats in ranges as we do for match in general (to make this easier to teach), so if we're going to allow those I'd prefer to reach a decision on all floats. |
What are the next steps on this PR? @withoutboats @nikomatsakis |
I think we should go forward with the PR for now. I'm still vaguely unhappy about the whole situation, but warnings seem ok and are a decent way to gain feedback too. |
@bors r+ |
📌 Commit 37fb676 has been approved by |
⌛ Testing commit 37fb676 with merge 497d628... |
💔 Test failed - status-travis |
@bors: retry
|
…omatsakis Implement the illegal_floating_point_literal_pattern compat lint Adds a future-compatibility lint for the [breaking-change] introduced by issue rust-lang#41620 . cc issue rust-lang#41255 .
Remove debug message It was added by me in rust-lang#41293. Sorry about that! Thanks goes to @alexbool for finding it.
Remove debug message It was added by me in rust-lang#41293. Sorry about that! Thanks goes to @alexbool for finding it.
Adds a future-compatibility lint for the [breaking-change] introduced by issue #41620 . cc issue #41255 .