Closed
Description
Consider the following code:
trait Foo {}
fn bar(_: impl Iterator<Item = Foo>) {}
// Or another similar case:
trait Bar {
type X: Iterator<Item = Foo>;
}
The current output is:
error[E0782]: trait objects must include the `dyn` keyword
--> src/lib.rs:3:32
|
3 | fn bar(_: impl Iterator<Item = Foo>) {}
| ^^^
|
help: add `dyn` keyword before this trait
|
3 | fn bar(_: impl Iterator<Item = dyn Foo>) {}
| +++
This is reasonable especially in light of the ongoing migration from the old dyn
-less trait object syntax. However, an alternative interpretation of the syntax error is that the user accidentally used a type equality bound =
when they actually meant a trait bound :
. The error message could include a suggestion to replace =
with :
.
help: or if you meant to write a trait bound, replace `=` with `:`
|
3 | fn bar(_: impl Iterator<Item = Foo>) {}
| --
3 | fn bar(_: impl Iterator<Item: Foo>) {}
| +
See also related #99304 which proposes that impl Foo
should be suggested rather than dyn Foo
.