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

needless_lifetimes false positive, which leads to unsound code #9360

Closed
matklad opened this issue Aug 22, 2022 · 2 comments · Fixed by #10222
Closed

needless_lifetimes false positive, which leads to unsound code #9360

matklad opened this issue Aug 22, 2022 · 2 comments · Fixed by #10222
Labels
C-bug Category: Clippy is not doing the correct thing L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@matklad
Copy link
Member

matklad commented Aug 22, 2022

Summary

See jeromefroe/lru-rs#153

Reproducer

No response

Version

No response

Additional Labels

No response

@matklad matklad added the C-bug Category: Clippy is not doing the correct thing label Aug 22, 2022
@Jarcho
Copy link
Contributor

Jarcho commented Aug 22, 2022

Is there a reason pub fn peek_lru(&self) -> Option<(&K, &V)> is wrong? The lint could use a suggestion.

@matklad
Copy link
Member Author

matklad commented Aug 22, 2022

Hm, actually you are right! The error message isn't inherently misleading:

    Checking lru v0.7.8 (/home/matklad/p/lru-rs)
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
   --> src/lib.rs:489:5
    |
489 |     pub fn get_or_insert<'a, F>(&'a mut self, k: K, f: F) -> &'a V
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `-D clippy::needless-lifetimes` implied by `-D warnings`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes

we can fully rely on elision here. But yeah, I think adding a suggestion here would help to make sure that all 'a's are removed

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 L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants