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

unused-lifetimes lint duplicates "parameter is never used" error #72587

Closed
Tracked by #94038
Aaron1011 opened this issue May 25, 2020 · 2 comments · Fixed by #122251
Closed
Tracked by #94038

unused-lifetimes lint duplicates "parameter is never used" error #72587

Aaron1011 opened this issue May 25, 2020 · 2 comments · Fixed by #122251
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Aaron1011
Copy link
Member

The following code:

#![warn(unused_lifetimes)]
struct Foo<'a>;

fn main() {}

gives the following output:

arning: lifetime parameter `'a` never used
 --> unused_lifetime.rs:2:12
  |
2 | struct Foo<'a>;
  |           -^^- help: elide the unused lifetime
  |
note: the lint level is defined here
 --> unused_lifetime.rs:1:9
  |
1 | #![warn(unused_lifetimes)]
  |         ^^^^^^^^^^^^^^^^

error[E0392]: parameter `'a` is never used
 --> unused_lifetime.rs:2:12
  |
2 | struct Foo<'a>;
  |            ^^ unused parameter
  |
  = help: consider removing `'a`, referring to it in a field, or using a marker such as `std::marker::PhantomData`

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0392`.

The "unused lifetimes" warning is redundant - not using a lifetime parameter is a hard error, so the warning gives no additional information.

@Aaron1011 Aaron1011 added C-bug Category: This is a bug. A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. labels May 25, 2020
@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 25, 2020
@awoimbee
Copy link
Contributor

Note that this lint still makes sense for functions:

#![warn(unused_lifetimes)]
fn unused_lifetime<'a>() {}
fn main() {unused_lifetime();}
   Compiling aaaaaa v0.1.0 (/tmp/aaaaaa)
warning: lifetime parameter `'a` never used
 --> src/main.rs:3:20
  |
3 | fn unused_lifetime<'a>() {}
  |                   -^^- help: elide the unused lifetime
  |
note: lint level defined here
 --> src/main.rs:1:9
  |
1 | #![warn(unused_lifetimes)]
  |         ^^^^^^^^^^^^^^^^

    Finished dev [unoptimized + debuginfo] target(s) in 0.16s

But then running clippy on the following looks dumb (the lints are redundant):

#![warn(unused_lifetimes)]
#![warn(clippy::extra_unused_lifetimes)]
fn unused_lifetime<'a>() {}
fn main() {
	unused_lifetime();
}
    Checking aaaaaa v0.1.0 (/tmp/aaaaaa)
warning: lifetime parameter `'a` never used
 --> src/main.rs:3:20
  |
3 | fn unused_lifetime<'a>() {}
  |                   -^^- help: elide the unused lifetime
  |
note: lint level defined here
 --> src/main.rs:1:9
  |
1 | #![warn(unused_lifetimes)]
  |         ^^^^^^^^^^^^^^^^

warning: this lifetime isn't used in the function definition
 --> src/main.rs:3:20
  |
3 | fn unused_lifetime<'a>() {}
  |                    ^^
  |
note: lint level defined here
 --> src/main.rs:2:9
  |
2 | #![warn(clippy::extra_unused_lifetimes)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes

    Finished dev [unoptimized + debuginfo] target(s) in 0.10s

I don't really know the compiler internals, but should this lint just skip structs ? (is that even possible ?)

@oskgo
Copy link
Contributor

oskgo commented Jan 25, 2024

@rustbot label +E-needs-test

This was fixed in #96833 but no test was added for nonduplication.

@rustbot rustbot added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jan 25, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 9, 2024
…st, r=Nadrieril

Add test to check unused_lifetimes don't duplicate "parameter is never used" error

Closes rust-lang#72587.
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Mar 10, 2024
…st, r=Nadrieril

Add test to check unused_lifetimes don't duplicate "parameter is never used" error

Closes rust-lang#72587.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 10, 2024
…st, r=Nadrieril

Add test to check unused_lifetimes don't duplicate "parameter is never used" error

Closes rust-lang#72587.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 10, 2024
…st, r=Nadrieril

Add test to check unused_lifetimes don't duplicate "parameter is never used" error

Closes rust-lang#72587.
jhpratt added a commit to jhpratt/rust that referenced this issue Mar 10, 2024
…st, r=Nadrieril

Add test to check unused_lifetimes don't duplicate "parameter is never used" error

Closes rust-lang#72587.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 10, 2024
…st, r=Nadrieril

Add test to check unused_lifetimes don't duplicate "parameter is never used" error

Closes rust-lang#72587.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 10, 2024
Rollup merge of rust-lang#122251 - jieyouxu:unused-lifetimes-dedup-test, r=Nadrieril

Add test to check unused_lifetimes don't duplicate "parameter is never used" error

Closes rust-lang#72587.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants