Skip to content

FN implicit if_same_then_else #3030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
matthiaskrgr opened this issue Aug 11, 2018 · 1 comment
Open

FN implicit if_same_then_else #3030

matthiaskrgr opened this issue Aug 11, 2018 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@matthiaskrgr
Copy link
Member

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?

@phansch phansch added the C-bug Category: Clippy is not doing the correct thing label Dec 11, 2018
@matthiaskrgr matthiaskrgr added the I-false-negative Issue: The lint should have been triggered on code, but wasn't label Dec 18, 2020
@felix91gr
Copy link
Contributor

I haven't been able to trigger the lint again with any of those examples.

Both do trigger the needless_return lint:

If we do as the needless_return lint says, we go back to the behavior you observed, @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
}
fn main() {
	println!("{:?}", func(4));
}

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

So I'd say the bug still stands as reported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

No branches or pull requests

3 participants