rust-lang / rust-lang/rust-clippy
restriction lint: subcondition side-effects
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
So disclaimer, I'm not sure if this is a necessary lint (anyone with input see my rust forum post https://users.rust-lang.org/t/evaluation-order-of-boolean-subconditions/13748). But I have the feeling that boolean subcondition execution order is probably not guaranteed like in C and C++. Therefore, if a user had side-effects in a subcondition program behaviour could change significantly due to something like a changed optimisation flag.
Below is some code which should be warned against if this lint is necessary. If this is an issue I wouldn't mind implementing the lint to help out 😄
fn side_effect(i: &mut i32) -> bool {
(*i) += 1;
true
}
fn main() {
let mut i = 4;
if false && side_effect(&mut i) {
//Some code
}
println!("i is {}", i);
if side_effect(&mut i) && false {
//Some code
}
println!("i is {}", i);
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the linked Rust forum discussion and the example in this issue, focusing on the intended evaluation-order and side-effect behavior. The issue does not name repository files or tests, and completion criteria for whether this lint is necessary or how it should behave are not defined.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100