Uh oh!
There was an error while loading. Please reload this page.
Fix various aspects around let bindings inside const functions - #56160
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Centril
left a comment
There was a problem hiding this comment.
Additionally, here's a comprehensive run-pass test that would be nice to add: https://gist.github.com/Centril/a8df54dc8ee0b6bf0da46b5fba446acd
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This comment has been minimized.
This comment has been minimized.
Uh oh!
There was an error while loading. Please reload this page.
@oli-obk Can we poison the MIR (i.e. add a flag that we set to |
Centril
commented
Nov 23, 2018
@oli-obk I remembered one thing now... floating points and assignment ops... we should make sure that they are not stabilized by including a test with all of the assignment ops for f32 & f64. :) |
Centril
commented
Nov 23, 2018
Having reviewed the main tests, I pass on the torch to... also cc @RalfJung and @nikomatsakis |
Uh oh!
There was an error while loading. Please reload this page.
eddyb
commented
Nov 23, 2018
@oli-obk Can you add tests for |
oli-obk
commented
Nov 23, 2018
I had the exact same idea like an hour ago. I guess that means it wasn't a stupid idea |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
RalfJung
commented
Nov 24, 2018
oli-obk
commented
Nov 26, 2018
I'm going to reintroduce the feature gate and let the final version bake a little more in nightly. I don't feel comfortable changing so many things and stabilizing at the same time. |
oli-obk
commented
Nov 26, 2018
Single match arms lead to |
eddyb
commented
Nov 26, 2018
@oli-obk Maybe because of the |
RalfJung
commented
Nov 26, 2018
Nit all single-arm matches should work, IMO. Just things like |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
let bindings inside const functionslet bindings inside const functions| } | ||
| } | ||
| fn const_let_allowed(&self) -> bool { |
There was a problem hiding this comment.
Seems like a great place for a comment =) in particular, documenting the logic behind these rules.
There was a problem hiding this comment.
Something like:
Currently, without a feature gate, let is only allowed in const fn. With a feature gate, it can appear anywhere.
There was a problem hiding this comment.
We decided on not doing this dual-scheme. Instead we're poisoning constants that use short circuiting operators so they can't also have let bindings.
I'll remove the function and move back to checking the feature gate directly
| op.span, | ||
| "`&&` operator".into(), | ||
| )); | ||
| ExprKind::Binary { |
There was a problem hiding this comment.
Woah. I don't think I realized we do this sort of conversion.
| if context.is_mutating_use() { | ||
| this.not_const() | ||
| } else { | ||
| this.qualif = Qualif::NOT_CONST; |
There was a problem hiding this comment.
Is this intentionally overriding all other Qualif flags? (vs invoking add)? Why is that? Maybe a comment?
There was a problem hiding this comment.
That is an accidental leftover from the larger refactorings. I undid the change and added comments
nikomatsakis
commented
Dec 11, 2018
First round of review -- I'd like to take one more look before r+ and in particular to know the answer to this question |
| @@ -0,0 +1,26 @@ | |||
| error: new features like let bindings are not permitted in constant which also use short circuiting operators | |||
There was a problem hiding this comment.
this reads oddly, it should be "in constants" -- i.e., plural
| error: new features like let bindings are not permitted in constant which also use short circuiting operators | ||
| --> $DIR/const_short_circuit.rs:6:9 | ||
| | | ||
| LL | let mut x = true && false; |
There was a problem hiding this comment.
also, I presume we intend this to be temporary? this restriction is very odd and surprising from an end-user point-of-view, I wonder if we can direct people to some kind of roadmap / URL that explains what the heck is going on?
nikomatsakis
commented
Dec 17, 2018
r=me modulo nits above |
oli-obk
commented
Dec 18, 2018
@bors r=nikomatsakis |
bors
commented
Dec 18, 2018
📌 Commit d815e2b has been approved by |
bors
commented
Dec 18, 2018
⌛ Testing commit d815e2b with merge 36b0f367a017ba709a4539a6873344e7ee62e756... |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bors
commented
Dec 18, 2018
Fix various aspects around `let` bindings inside const functions * forbid `let` bindings in const contexts that use short circuiting operators * harden analysis code against derefs of mutable references Initially this PR was about stabilizing `let` bindings, but too many flaws were exposed that need some more testing on nightly
bors
commented
Dec 18, 2018
☀️ Test successful - status-appveyor, status-travis |
letbindings in const contexts that use short circuiting operatorsInitially this PR was about stabilizing
letbindings, but too many flaws were exposed that need some more testing on nightly