Skip to content

restriction lint: subcondition side-effects #2215

Description

@xd009642

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);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.L-correctnessLint: Belongs in the correctness lint groupT-middleType: Probably requires verifiying types

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions