rust-lang / rust-lang/rust-clippy
Impl trait lifetime mismatch
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Detect impl items where the lifetimes do not match the trait item definition. I believe this can be more specifically described as having "stricter" lifetime requirements than the trait item definition.
Categories (optional)
- Kind: style
What is the advantage of the recommended code over the original code
Inconsistency between the trait and impl is confusing and less self-documenting. Also it may lead to preventable lifetime errors. Also, since the lifetime is already named and available in the impl block, it seems appropriate to use it wherever applicable.
Drawbacks
It is more convenient to elide lifetimes if the particular implementation allows it.
Example
trait Foo<'a> {
fn hi(a: &'a str, b: &'a str);
}
struct Bar;
struct Baz;
impl<'a> Foo<'a> for Bar {
// here the trait lifetime is unused
fn hi(_: &str, _: &str) {
unimplemented!()
}
}
impl<'a> Foo<'a> for Baz {
// here different lifetime semantics are applied
fn hi<'b>(_: &'b str, _: &'b str) {
unimplemented!()
}
}
Could be written as:
impl<'a> Foo<'a> for Bar {
fn hi(_: &'a str, _: &'a str) {
unimplemented!()
}
}
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
The issue names no files, tests, or entry points. Start by examining rust-clippy's existing lint infrastructure and how trait and impl item lifetimes are compared; done means the lint identifies the unused or stricter lifetime cases shown in the examples and provides regression coverage for them.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100