-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Wrong result after short circuit in const_let #53515
Comments
Uh.... Apparently short circuiting operators don't exist in consts: rust/src/librustc_mir/hair/cx/expr.rs Lines 328 to 358 in d2048b6
cc @eddyb Since we did not have a way to observe short circuiting before the Note that const fn is unnecessary: #![feature(const_let)]
const COND: bool = true;
const X: bool = {
let mut ret = true;
// If COND is true, we short circuit and ret remains true.
// If COND is false, we assign ret = false.
let _ = COND || { ret = false; true };
ret
};
fn main() {
println!("{}", X);
} |
Oh wow, whoops, at least we haven't stabilized anything that could observe this, whew. |
So where is the tracking issue to allow
|
@eddyb can we just mark any MIR containing |
What is the problem there? |
We need to check whether if T::FOO {
Some(Cell::new(42))
} else {
None
} results in a Since |
Oh, we are already more precise than the type is? |
I think the place that has the best information about this kind of stuff is the sanity check. So if we make that part of the query for constants, it could probably do this. |
(Noting that) this no longer compiles on nightly: error[E0019]: constant function contains unimplemented expression type
--> src/main.rs:8:13
|
8 | let _ = condition || { ret = false; true };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error |
So I think this can be closed because there's no longer an incorrect result. See #49146 for the tracking issue for control flow in |
I would expect this program to print
true
. As of rustc 1.30.0-nightly (33b923f 2018-08-18) it printsfalse
. If you changeconst fn
tofn
then it printstrue
as expected.Mentioning @oli-obk.
Mentioning const_let tracking issue #48821.
The text was updated successfully, but these errors were encountered: