Closed
Description
Code
trait Foo {
type Clone;
fn foo() -> Clone
}
Current output
error[E0782]: trait objects must include the `dyn` keyword
--> src/main.rs:4:17
|
4 | fn foo() -> Clone;
| ^^^^^
|
help: add `dyn` keyword before this trait
|
4 | fn foo() -> dyn Clone;
| +++
For more information about this error, try `rustc --explain E0782`.
Desired output
Obviously this isn't helpful, as Clone
isn't object safe. The correct error is E0412
:
error[E0412]: cannot find type `Clone` in this scope
--> src/main.rs:4:17
|
4 | fn foo() -> Clone;
| ^^^
|
help: you might have meant to use the associated type
|
4 | fn foo() -> Self::Clone;
| ++++++
For more information about this error, try `rustc --explain E0412`.
Rationale and extra context
E0412
is correctly emitted if the associated type name is changed to not collide with any traits currently in scope. So:
trait Foo {
type Bar;
fn foo() -> Bar
}
Errors as expected.
I've also seen this confuse new users "in the wild" on Rustcord - that's what originally inspired me to file this issue.
Other cases
No response
Anything else?
No response