Skip to content

needless_return has false negative pattern #8978

Closed
@kyoto7250

Description

@kyoto7250

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

Metadata

Metadata

Assignees

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