Skip to content

E0308 should suggest .into() if available #102415

Closed

Description

Given:

fn main() {
    let x: A = B;
}

struct A;
struct B;

impl From<B> for A {
    fn from(_: B) -> Self { A }
}

the current output is

error[E0308]: mismatched types
 --> src/main.rs:2:16
  |
2 |     let x: A = B;
  |            -   ^ expected struct `A`, found struct `B`
  |            |
  |            expected due to this

but we should probe for possible Into and From impls and suggest them if reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-papercutDiagnostics: An error or lint that needs small tweaks.T-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