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

Incorrect unnecessary_lazy_evaluations suggestion #6052

Closed
chrisduerr opened this issue Sep 16, 2020 · 3 comments
Closed

Incorrect unnecessary_lazy_evaluations suggestion #6052

chrisduerr opened this issue Sep 16, 2020 · 3 comments
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@chrisduerr
Copy link
Contributor

It seems like clippy has problems detecting if a lazy evaluation is unnecessary when calling a function inside the closure and accessing fields on that returned value. I'm pretty sure this is a new issue since CI hasn't caught it previously.

This example should show what's wrong:

fn main() {
    let _ = Some(3).unwrap_or_else(|| foo().0);
    let _ = Some(3).unwrap_or_else(|| bar().a);
}

fn foo() -> (usize, usize) {
    (0, 0)
}

struct X { a: usize }
fn bar() -> X {
    X { a: 0 }
}

This shouldn't be allowed since the foo and bar function could obviously be very expensive. So unwrap_or isn't the correct function to use.

@chrisduerr chrisduerr added the C-bug Category: Clippy is not doing the correct thing label Sep 16, 2020
@flip1995
Copy link
Member

Maybe this is fixed with #5937. cc @montrivo

@tnielens
Copy link
Contributor

The pr seems to correct this case. I checked by running uitest on the example.

@flip1995
Copy link
Member

Thanks for checking. Closing this, since #5937 doesn't auto-close it.

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
Projects
None yet
Development

No branches or pull requests

3 participants