Closed
Description
Given the following code:
struct Foo {
inner: u32,
}
struct Bar {
inner: u32,
}
#[derive(Clone, Copy)]
struct Baz {
inner: u32,
}
impl From<Baz> for Bar {
fn from(other: Baz) -> Self {
Self {
inner: other.inner,
}
}
}
impl From<Baz> for Foo {
fn from(other: Baz) -> Self {
Self {
inner: other.inner,
}
}
}
fn main() {
let x: Baz = Baz { inner: 42 };
// DOESN'T Compile: Multiple options!
let y = x.into();
let y_1: Foo = x.into();
let y_2: Bar = x.into();
let z_1 = Foo::from(y_1);
let z_2 = Bar::from(y_2);
// No type annotations needed, the compiler KNOWS the type must be `Foo`!
let m = magic_foo(x);
}
fn magic_foo(arg: Baz) -> Foo {
arg.into()
}
The current output is:
error[E0282]: type annotations needed
--> src/main.rs:34:9
|
34 | let y = x.into();
| ^ consider giving `y` a type
error: aborting due to previous error
For more information about this error, try `rustc --explain E0282`.
Ideally the output should look like:
IMO the output could include:
- A reminder of the explicit type syntax (e.g.
let y: TYPE = x.into()
)- This is well suggested in
rustc --explain E0282
, but it might be helpful in the rustc output as well
- This is well suggested in
- A suggestion of potential candidate (e.g. in this case:
Foo
orBar
)
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Type inferenceArea: Trait systemDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.Relevant to the compiler team, which will review and decide on the PR/issue.