Skip to content

from_over_into suggests turning Into into conflicting From #16823

@malthesr

Description

@malthesr

Summary

For a newtype like struct Foo(String), Rust permits impl<T> From<T> for Foo where String: From<T>. In the presence of this, impl From<Foo> for String is not allowed due to conflicting implementations, but as a workaround impl Into<String> for Foo is permitted. However, clippy suggests turning the latter into the former.

Lint Name

from_over_into

Reproducer

I tried this code:

pub struct Foo(pub String);

impl<T> From<T> for Foo
where
    String: From<T>,
{
    fn from(label: T) -> Self {
        Self(String::from(label))
    }
}

// Triggers `clippy::from_over_into`.
impl Into<String> for Foo {
    fn into(self) -> String {
        self.0
    }
}

// Suggestion from `clippy::from_over_into`. Uncommenting gives:
//
// ```
// error[E0119]: conflicting implementations of trait `From<Foo>` for type `Foo`
//  --> src/lib.rs:3:1
//   |
// 3 | / impl<T> From<T> for Foo
// 4 | | where
// 5 | |     String: From<T>,
//   | |____________________^
//   |
//   = note: conflicting implementation in crate `core`:
//           - impl<T> From<T> for T;
// ```
// impl From<Foo> for String {
//     fn from(foo: Foo) -> Self {
//         foo.0
//     }
// }

(Playground)

I saw this happen:

warning: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
  --> src/lib.rs:13:1
   |
13 | impl Into<String> for Foo {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: `impl From<Local> for Foreign` is allowed by the orphan rules, for more information see
           https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.94.0/index.html#from_over_into
   = note: `#[warn(clippy::from_over_into)]` on by default
help: replace the `Into` implementation with `From<Foo>`
   |
13 ~ impl From<Foo> for String {
14 ~     fn from(val: Foo) -> Self {
15 ~         val.0
   |

I expected to see this happen: Clippy not suggesting a fix that results in compiler error.

Version

Tested both stable and latest beta:

rustc 1.95.0-beta.7 (cc969f3c4 2026-04-03)
binary: rustc
commit-hash: cc969f3c457b2ce350fb9fda6c784cc9813b5c71
commit-date: 2026-04-03
host: x86_64-unknown-linux-gnu
release: 1.95.0-beta.7
LLVM version: 22.1.2
rustc 1.94.1 (e408947bf 2026-03-25)
binary: rustc
commit-hash: e408947bfd200af42db322daf0fadfe7e26d3bd1
commit-date: 2026-03-25
host: x86_64-unknown-linux-gnu
release: 1.94.1
LLVM version: 21.1.8

Additional Labels

No response

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 have

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions