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

[FP] extra_unused_lifetimes can be triggered by a derive macro #9014

Closed
JohnTitor opened this issue Jun 18, 2022 · 0 comments · Fixed by #9037
Closed

[FP] extra_unused_lifetimes can be triggered by a derive macro #9014

JohnTitor opened this issue Jun 18, 2022 · 0 comments · Fixed by #9037
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

@JohnTitor
Copy link
Member

Summary

Consider this code:

/// Represents a new user record insertable to the `users` table
#[derive(Insertable, Debug, Default)]
#[table_name = "users"]
pub struct NewUser<'a> {
    pub gh_id: i32,
    pub gh_login: &'a str,
    pub name: Option<&'a str>,
    pub gh_avatar: Option<&'a str>,
    pub gh_access_token: Cow<'a, str>,
}

(The code is from the crates.io source code)

The struct itself needs the 'a lifetime, but notice we use the Insertable derive macro from the Diesel.
Insertable will trigger extra_unused_lifetimes and cause the below warning:

warning: this lifetime isn't used in the impl
  --> src/models/user.rs:26:10
   |
26 | #[derive(Insertable, Debug, Default)]
   |          ^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes
   = note: this warning originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more info)

But you cannot fix it as the warning comes from the outside of your code.

Lint Name

extra_unused_lifetimes

Reproducer

I tried this code:

/// Represents a new user record insertable to the `users` table
#[derive(Insertable, Debug, Default)]
#[table_name = "users"]
pub struct NewUser<'a> {
    pub gh_id: i32,
    pub gh_login: &'a str,
    pub name: Option<&'a str>,
    pub gh_avatar: Option<&'a str>,
    pub gh_access_token: Cow<'a, str>,
}

I saw this happen:

warning: this lifetime isn't used in the impl
  --> src/models/user.rs:26:10
   |
26 | #[derive(Insertable, Debug, Default)]
   |          ^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes
   = note: this warning originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more info)

I expected to see this happen:

No warnings.

Version

rustc 1.63.0-nightly (c3b7d7b49 2022-06-17)
binary: rustc
commit-hash: c3b7d7b496b5536bb0a3d501222d2d0a8b54a69e
commit-date: 2022-06-17
host: x86_64-unknown-linux-gnu
release: 1.63.0-nightly
LLVM version: 14.0.5

Additional Labels

No response

@JohnTitor JohnTitor 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 Jun 18, 2022
@bors bors closed this as completed in 1d1ae10 Jun 24, 2022
dswij added a commit to dswij/rust-clippy that referenced this issue Jun 24, 2022
This commit adds test for a `extra_unused_lifetimes` false positive from derive (rust-lang#9014).

The fix for the FP is introduced in rust-lang#9037.
dswij added a commit to dswij/rust-clippy that referenced this issue Jun 24, 2022
This commit adds test for a `extra_unused_lifetimes` false positive from derive (rust-lang#9014).

The fix for the FP is introduced in rust-lang#9037.
bors added a commit that referenced this issue Jun 29, 2022
`extra_unused_lifetimes` add FP test case emitting from derived attributes.

Add test to cover for #9014 which is fixed in #9037.

changelog: [`extra_unused_lifetimes`] Add FP test case emitting from derived attributes.

---

Seeing the FP from the test:

```sh
$ git revert -m 1 1d1ae10
$ TESTNAME=extra_unused_lifetime cargo uitest
```
jjlin added a commit to jjlin/vaultwarden that referenced this issue Jul 1, 2022
The latest version (1.62.0) that was just released includes Clippy changes
(rust-lang/rust-clippy#9014) that break the build.
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