Skip to content

lint: warn about identical conditions inside and outside of functions #2278

Open
@matthiaskrgr

Description

@matthiaskrgr

There could be a warning if something is checked outside of a function, passed inside the function and then checked inside the function again.
This might spot redundant conditions but also logic errors if the conditions are conflicting.

fn fun(awesomestruct: SomeStruct) {
   if awesomestruct.bar { return } // check inside function
   [...]
}

fn main() {
    let struct: SomeStruct = something(); 

    if struct.bar { // same condition that is inside of function
         fun(struct);
    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsE-hardCall for participation: This a hard problem and requires more experience or effort to work onL-correctnessLint: Belongs in the correctness lint groupL-unnecessaryLint: Warn about unnecessary codeT-MIRType: This lint will require working with the MIRT-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