Skip to content

FN implicit if_same_then_else #3030

Open
@matthiaskrgr

Description

@matthiaskrgr
fn main() {
	println!("{:?}", func(4));
}

fn func(n: i32) -> bool {
	if n < 2 {
		return true;
	} else if  n > 2 {
		return false;
	}
	return false; // return outside of conditions
}

this code is basically identical to

fn main() {
	println!("{:?}", func(4));
}

fn func(n: i32) -> bool {
	if n < 2 {
		return true;
	} else if  n > 2 {
		return false;
	} else { // return moved into else {}
		return false;
	}
}

but only the latter triggers the if_same_then_else warning.
Should the first example trigger a warning as well?

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions