rust-lang / rust-lang/rust-clippy
needless_lifetimes suggestion forgets to remove some lifetimes
Open
Nobody has claimed this yet.
C-bug
I-suggestion-causes-error
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
clippy leaves in one of lifetimes and thus the code fails to compile
9 - fn f<'a>(PhantomData::<&'a u8>: PhantomData<&'a u8>) {}
9 + fn f(PhantomData::<&'a u8>: PhantomData<&u8>) {}
Reproducer
I tried this code:
#![allow(dead_code)]
use std::marker::PhantomData;
fn f<'a>(PhantomData::<&'a u8>: PhantomData<&'a u8>) {}
fn main() {}
I expected to see this happen:
warning: the following explicit lifetimes could be elided: 'a
--> src/main.rs:9:1
|
9 | fn f<'a>(PhantomData::<&'a u8>: PhantomData<&'a u8>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
= note: `#[warn(clippy::needless_lifetimes)]` on by default
help: elide the lifetimes
|
9 - fn f<'a>(PhantomData::<&'a u8>: PhantomData<&'a u8>) {}
9 + fn f(PhantomData::<&u8>: PhantomData<&u8>) {}
Instead, this happened:
warning: the following explicit lifetimes could be elided: 'a
--> src/main.rs:9:1
|
9 | fn f<'a>(PhantomData::<&'a u8>: PhantomData<&'a u8>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
= note: `#[warn(clippy::needless_lifetimes)]` on by default
help: elide the lifetimes
|
9 - fn f<'a>(PhantomData::<&'a u8>: PhantomData<&'a u8>) {}
9 + fn f(PhantomData::<&'a u8>: PhantomData<&u8>) {}
Version
rustc 1.70.0-nightly (8a73f50d8 2023-03-11)
binary: rustc
commit-hash: 8a73f50d875840b8077b8ec080fa41881d7ce40d
commit-date: 2023-03-11
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 15.0.7
Additional Labels
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the needless_lifetimes lint and run the provided PhantomData reproducer to observe the incorrect suggestion. The fix is complete when the suggested replacement removes every 'a lifetime and the resulting Rust code compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100