Skip to content

clippy::useless_conversion suggested fix breaks code with lifetimes #14322

@m-mueller678

Description

@m-mueller678

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.

rust playground

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions