Closed
Description
In certain circumstances, true != !false
is considered true
.
Steps to reproduce
- Create a new project with
cargo new negation --bin
- Change the file
src/main.rs
so that the contents is the following:
fn g() -> bool {
false
}
fn main() {
let a = !g();
if a != !g() {
println!("wrong");
} else {
println!("correct");
}
}
3.Run with cargo run
Expected and observed behavior
When run with cargo run
, the compiled program prints wrong
.
I expect correct
to be printed because after the assignment,
a
should still equal the value it was assigned to (note that g()
always
returns the same value).
Note that cargo run --release
results in printing correct
, so even if it's me who is being confused, the output should still be the same in debug mode and in release mode.
Meta
When I do a normal rustc main.rs
and witch cargo run --release
the resulting
program behaves as I expect.
The unexpected behaviour only occurs when using cargo run
(or running target/debug/negation
).
rustc --version --verbose
:
rustc 1.12.0 (3191fbae9 2016-09-23)
binary: rustc
commit-hash: 3191fbae9da539442351f883bdabcad0d72efcb6
commit-date: 2016-09-23
host: x86_64-unknown-linux-gnu
release: 1.12.0
cargo --version --verbose
cargo 0.13.0-nightly (109cb7c 2016-08-19)
Edit: added short description.