-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Confusion with double negation and booleans #36856
Copy link
Copy link
Closed
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Description
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Type
Fields
Give feedbackNo fields configured for issues without a type.
In certain circumstances,
true != !falseis consideredtrue.Steps to reproduce
cargo new negation --binsrc/main.rsso that the contents is the following:3.Run with
cargo runExpected and observed behavior
When run with
cargo run, the compiled program printswrong.I expect
correctto be printed because after the assignment,ashould still equal the value it was assigned to (note thatg()alwaysreturns the same value).
Note that
cargo run --releaseresults in printingcorrect, 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.rsand witchcargo run --releasethe resultingprogram behaves as I expect.
The unexpected behaviour only occurs when using
cargo run(or runningtarget/debug/negation).rustc --version --verbose:cargo --version --verboseEdit: added short description.