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

"warning: unnecessary lifetime parameter" unsilenceable lint #96956

Closed
ijackson opened this issue May 11, 2022 · 17 comments · Fixed by #108230, paritytech/parity-common#748 or paritytech/substrate#14096
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. P-medium Medium priority regression-untriaged Untriaged performance or correctness regression. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ijackson
Copy link
Contributor

ijackson commented May 11, 2022

Given the following code:

pub fn thing<'a>(_s: &'a str) where 'a: 'static { }

The current output is:

warning: unnecessary lifetime parameter `'a`
 --> src/lib.rs:2:37
  |
2 | pub fn thing<'a>(_s: &'a str) where 'a: 'static { }
  |                                     ^^
  |
  = help: you can use the `'static` lifetime directly, in place of `'a`

warning: `playground` (lib) generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 1.27s

Ideally the output should also say something like this:

  = note: `#[warn(needless_lifetimes)]` on by default

And of course then #[allow(needless_lifetimes)] ought to work.

Versions affected

rustcargo@zealot:/volatile/rustcargo/Rustup/Game/server$ rustc -vV
rustc 1.62.0-nightly (ecd44958e 2022-05-10)
binary: rustc
commit-hash: ecd44958e0a21110d09862ee080d95a4ca6c52f8
commit-date: 2022-05-10
host: x86_64-unknown-linux-gnu
release: 1.62.0-nightly
LLVM version: 14.0.1
rustcargo@zealot:/volatile/rustcargo/Rustup/Game/server$ 

The example code is accepted without any complaint by stable and beta, However, in both stable and beta, clippy has the same weird name-less complaint. And saying #![allow(clippy::needless_lifetimes)] doesn't suppress the message.

I searched for "lifetime" in the clippy lints db. Of those that came up, needless_lifetimes and redundant_static_lifetimes seemed like they might be it, but neither of those suppresses the lint on stable's clippy.

@ijackson ijackson added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 11, 2022
@ijackson
Copy link
Contributor Author

@rustbot modify labels +regresson-from-stable-to-nightly

@rustbot
Copy link
Collaborator

rustbot commented May 11, 2022

Error: Label regresson-from-stable-to-nightly can only be set by Rust team members

Please let @rust-lang/release know if you're having trouble with this bot.

@gimbling-away

This comment was marked as off-topic.

@ijackson
Copy link
Contributor Author

This is not a clippy lint. It is being emitted, here, by rustc:

rustcargo@zealot:~$ cat t.rs
pub fn thing<'a>(_s: &'a str) where 'a: 'static { }
fn main() { thing(""); }
rustcargo@zealot:~$ rustc +nightly t.rs
warning: unnecessary lifetime parameter `'a`
 --> t.rs:1:37
  |
1 | pub fn thing<'a>(_s: &'a str) where 'a: 'static { }
  |                                     ^^
  |
  = help: you can use the `'static` lifetime directly, in place of `'a`

warning: 1 warning emitted

rustcargo@zealot:~$ 

The situation is confusing because there is (or was?) also a clippy lint for this; I think this may have been promoted into rustc but something was done wrong there.

I have rechecked and:

  • rustc 1.61.0 (fe5b13d68 2022-05-18) (stable) unaffected
  • rustc 1.62.0-beta.2 (daf68b1f7 2022-05-19) affected
  • rustc 1.63.0-nightly (4cbaac699 2022-05-25) affected

@rust-lang/release could you please set the regresson-from-stable-to-beta label for me?

@ijackson ijackson changed the title "warning: unnecessary lifetime parameter" doesn't have (or print?) lint name? "warning: unnecessary lifetime parameter" unsilenceable lint May 26, 2022
@ijackson
Copy link
Contributor Author

@rustbot ping rust-lang/release

@rustbot
Copy link
Collaborator

rustbot commented May 26, 2022

Error: Only Rust team members can ping teams.

Please let @rust-lang/release know if you're having trouble with this bot.

@ijackson
Copy link
Contributor Author

@rustbot modify labels +regression-untriaged

@rustbot rustbot added regression-untriaged Untriaged performance or correctness regression. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels May 26, 2022
@ijackson
Copy link
Contributor Author

Ah! Looking at the "Regression" bug template gave me a hint.

@gimbling-away
Copy link
Contributor

Ahh, I see. I was testing on stable, my bad.

@apiraino
Copy link
Contributor

apiraino commented Jun 7, 2022

bisected the regression (with cargo-bisect) points to pr #93803 (cc @cjgillot )

searched nightlies: from nightly-2022-02-01 to nightly-2022-06-07
regressed nightly: nightly-2022-05-01
searched commit range: a707f40...7c4b476
regressed commit: d201c81

bisected with cargo-bisect-rustc v0.6.1

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --start=2022-02-01 --script=./test.sh 

@apiraino
Copy link
Contributor

apiraino commented Jun 7, 2022

Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jun 7, 2022
@cjgillot
Copy link
Contributor

cjgillot commented Jun 7, 2022

#93803 made this warning more precise, so it triggers more often.
This is a hard-warning. Fixing it requires to turn it into a lint.

Steps:

  • declare the lint in rustc_lint_defs::builtin and write a proper explanation;
  • in rustc_resolve::late::lifetimes, replace the call to struct_span_warn by struct_span_lint_hir, the reference HirId is the bounded lifetime's one;
  • (option) move the lint to rustc_typeck::collect, to where RegionPredicate is processed.

@cjgillot cjgillot added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. E-help-wanted Call for participation: Help is requested to fix this issue. labels Jun 7, 2022
@gimbling-away
Copy link
Contributor

@rustbot claim

@gimbling-away gimbling-away removed their assignment Jun 13, 2022
@gimbling-away
Copy link
Contributor

I really apologize for this, I'm mostly busy with life and can't really find the time for working on this, feel free to pick it 💜

@jeremydavis519
Copy link

@rustbot claim

@Noratrieb
Copy link
Member

PR was closed due to inactivity, feel free to claim it again. @rustbot release-assignment

@LittleFall
Copy link
Contributor

@rustbot claim

compiler-errors added a commit to compiler-errors/rust that referenced this issue Feb 21, 2023
…bank

Convert a hard-warning about named static lifetimes into lint "unused_lifetimes"

Fixes rust-lang#96956.

Some changes are ported from rust-lang#98079, thanks to jeremydavis519.

r? `@estebank` `@petrochenkov`

Any feedback is appreciated!

## Actions
- [x] resolve conflicts
- [x] fix build
- [x] address review comments in last pr
- [x] update tests
@bors bors closed this as completed in a32c500 Feb 22, 2023
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 E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. P-medium Medium priority regression-untriaged Untriaged performance or correctness regression. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
8 participants