rust-lang / rust-lang/rust-clippy
clippy::useless_conversion suggested fix breaks code with lifetimes
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
clippy::useless_conversion is issued when Into is used to convert to the same type but with different lifetime. The suggested fix breaks the code.
Lint Name
useless_conversion
Reproducer
I tried this code:
pub trait MyTrait {
type Borrowed<'a>;
}
pub fn make_static<T: MyTrait>(x: T::Borrowed<'_>) -> T::Borrowed<'static>
where
for<'a> T::Borrowed<'a>: Into<T::Borrowed<'static>>,
{
x.into()
}
I saw this happen:
|
9 | x.into()
| ^^^^^^^^ help: consider removing `.into()`: `x`
This breaks:
pub fn make_static<T: MyTrait>(x: T::Borrowed<'_>) -> T::Borrowed<'static>
where
for<'a> T::Borrowed<'a>: Into<T::Borrowed<'static>>,
{
x
}
9 | x
| ^ returning this value requires that `'1` must outlive `'static`
Version
rust stable 1.85.0
clippy 0.1.85 (2025-02-17 4d91de4e48)
Additional Labels
@rustbot label +I-suggestion-causes-error
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 useless_conversion lint and run the linked Rust Playground reproducer on the stated stable and Clippy versions. Trace how the lint builds its removal suggestion for lifetime-dependent associated types; done means the suggestion no longer produces the shown lifetime error while valid useless conversions remain diagnosed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100