Skip to content

Suppress needless_late_init on if-let and long if/match expr #8613

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

Closed
dhardy opened this issue Mar 31, 2022 · 0 comments · Fixed by #8617
Closed

Suppress needless_late_init on if-let and long if/match expr #8613

dhardy opened this issue Mar 31, 2022 · 0 comments · Fixed by #8617
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@dhardy
Copy link

dhardy commented Mar 31, 2022

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

@dhardy dhardy added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Mar 31, 2022
@bors bors closed this as completed in 95396f6 Apr 27, 2022
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-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant