Skip to content

Confusing error for missing From impls (and other traits with blanket impls) #104712

Closed

Description

@afetisov

Given the following code:

struct A;
struct B;

fn foo() {
    let a = A;
    let b = B::from(a);
}

The current output is:

error[[E0308]](https://doc.rust-lang.org/stable/error-index.html#E0308): mismatched types
 --> src/lib.rs:6:21
  |
6 |     let b = B::from(a);
  |             ------- ^ expected struct `B`, found struct `A`
  |             |
  |             arguments to this function are incorrect
  |
note: associated function defined here

Ideally the output should look like:

error: type `B` doesn't implement `From<A>` 
 --> src/lib.rs:6:21
  |
6 |     let b = B::from(a);
  |             ------- ^ expected struct `B`, found struct `A`
  |
note: type `B` has a blanket implementation
    impl<T> From<T> for T

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Nov 22, 2022
  2. steffahn commented on Nov 22, 2022

    @steffahn
    Member

    I guess it makes sense to also leave a link to the URLO discussion where we’re coming from.

  3. self-assigned this
    on Oct 21, 2026
  4. estebank commented on Oct 21, 2026

    @estebank
    Contributor

    Do people think the following which is introduced by #164702 is enough?

    error[E0308]: mismatched types
       --> tests/ui/fn_traits/point-at-impl-in-call-argument-type-error.rs:9:21
        |
      9 |     let b = B::from(a); //~ ERROR: mismatched types
        |             ------- ^ expected `B`, found `A`
        |             |
        |             arguments to this function are incorrect
        |
    note: associated function defined here
       --> library/core/src/convert/mod.rs:594:8
        |
    588 | pub const trait From<T>: Sized {
    ...
    594 |     fn from(value: T) -> Self;
        |        ^^^^
    note: associated function provided through this blanket `impl`
       --> library/core/src/convert/mod.rs:787:1
        |
    787 | const impl<T> From<T> for T {
        | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
  5. added 3 commits that reference this issue on Oct 26, 2026
    8b2eb07
    434c7a4
    1b12e8b
  6. added a commit that references this issue on Oct 26, 2026
    10fc9f4
  7. added a commit that references this issue on Oct 26, 2026
    78ddce9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions