0487500776
Add the following suggestions: ``` error[E0782]: trait objects must include the `dyn` keyword --> $DIR/not-on-bare-trait-2021.rs:11:11 | LL | fn bar(x: Foo) -> Foo { | ^^^ | help: use a generic type parameter, constrained by the trait `Foo` | LL | fn bar<T: Foo>(x: T) -> Foo { | ++++++++ ~ help: you can also use `impl Foo`, but users won't be able to specify the type paramer when calling the `fn`, having to rely exclusively on type inference | LL | fn bar(x: impl Foo) -> Foo { | ++++ help: alternatively, use a trait object to accept any type that implements `Foo`, accessing its methods at runtime using dynamic dispatch | LL | fn bar(x: &dyn Foo) -> Foo { | ++++ error[E0782]: trait objects must include the `dyn` keyword --> $DIR/not-on-bare-trait-2021.rs:11:19 | LL | fn bar(x: Foo) -> Foo { | ^^^ | help: use `impl Foo` to return an opaque type, as long as you return a single underlying type | LL | fn bar(x: Foo) -> impl Foo { | ++++ help: alternatively, you can return an owned trait object | LL | fn bar(x: Foo) -> Box<dyn Foo> { | +++++++ + ```
18 lines
382 B
Rust
18 lines
382 B
Rust
// edition:2021
|
|
trait Foo {
|
|
fn dummy(&self) {}
|
|
}
|
|
|
|
// This should emit the less confusing error, not the more confusing one.
|
|
|
|
fn foo(_x: Foo + Send) {
|
|
//~^ ERROR trait objects must include the `dyn` keyword
|
|
}
|
|
fn bar(x: Foo) -> Foo {
|
|
//~^ ERROR trait objects must include the `dyn` keyword
|
|
//~| ERROR trait objects must include the `dyn` keyword
|
|
x
|
|
}
|
|
|
|
fn main() {}
|