Open
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