-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
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 have
Description
Summary
According to the lint docs, the sole justification for this lint is to reduce repetitive code. Yes, the examples in the docs look better as suggested, but others don't.
Slightly wordy but clean code:
let attr_widget;
if let Some(i) = index {
let attr = attrs.remove(i);
let (_, tokens) = parse_attr_group(attr.tokens)?;
attr_widget = syn::parse2(tokens)?;
} else {
attr_widget = Default::default();
}
Shorter code, but first line contains two =
tokens (ugly):
let attr_widget = if let Some(i) = index {
let attr = attrs.remove(i);
let (_, tokens) = parse_attr_group(attr.tokens)?;
syn::parse2(tokens)?
} else {
Default::default()
};
It's easy to imagine worse examples:
let foo = if let Some(bar) = thing.iter().find(|t| t.is_good()) {
...
} else {
...
};
Suggestion: suppress lint when first line of if
/ match
is long or includes an if let
binding.
Lint Name
needless_late_init
Reproducer
No response
Version
No response
Additional Labels
No response
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 have