Skip to content
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

needless_return has false negative pattern #8978

Open
kyoto7250 opened this issue Jun 9, 2022 · 2 comments
Open

needless_return has false negative pattern #8978

kyoto7250 opened this issue Jun 9, 2022 · 2 comments
Assignees
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

@kyoto7250
Copy link
Contributor

kyoto7250 commented Jun 9, 2022

Summary

There is a pattern that does not work even though needless_return is enabled.

playground is here.

Lint Name

needless_return

Reproducer

I tried this code:

#![warn(clippy::needless_return)]
const WORDS: [&[&str]; 2] = [&["foo"], &["bar"]];

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

fn issue() -> bool {
    return WORDS.iter().any(|&word| word == ["foo"]);
}

I expected to see this happen: There should be a suggestion as above follows.

fn issue() -> bool {
    WORDS.iter().any(|&word| word == ["foo"])
}

Instead, this happened: No happen.

Version

rustc 1.61 (stable)
clippy 1.63
@kyoto7250 kyoto7250 added 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 labels Jun 9, 2022
@dswij
Copy link
Member

dswij commented Jun 14, 2022

@rustbot claim

@torokati44
Copy link

A bit more simplified reproducer:

#![warn(clippy::needless_return)]
fn main() {
    println!("{:?}", issue());
}

fn issue() -> bool {
    return [].iter().any(|_: &i32| false);
}

Referencing: ruffle-rs/ruffle#16906 (comment)

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

Successfully merging a pull request may close this issue.

3 participants