-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when appliedgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
Description
Lint name: manual_flatten
I tried this code:
struct Test {
a: Option<usize>,
b: Option<usize>,
}
fn main() {
let t = Test {
a: Some(1),
b: Some(2),
};
for x in [&t.a, &t.b] {
if let Some(y) = x {
println!("{}", y);
}
}
}
This also applies to mutable references.
Clippy suggests this, which is both incomplete as a refactor and does not compile. Try as I might I could not get into_iter().flatten() to compile.
for x in [&t.a, &t.b].into_iter().flatten() {
if let Some(y) = x {
println!("{}", y);
}
}
Meta
I saw #6893 which appears to be the same issue, but it was claimed to be fixed there and that fix should have landed in 1.53. I'm on 1.54 now and still seeing it with both mutable and immutable reference slices.
cargo clippy -V
: clippy 0.1.54 (a178d03 2021-07-26)rustc -Vv
:
rustc 1.54.0 (a178d0322 2021-07-26)
binary: rustc
commit-hash: a178d0322ce20e33eac124758e837cbd80a6f633
commit-date: 2021-07-26
host: x86_64-unknown-linux-gnu
release: 1.54.0
LLVM version: 12.0.1
ulrichstark
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when appliedgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy