|
| 1 | +error[E0782]: trait objects must include the `dyn` keyword |
| 2 | + --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:4:13 |
| 3 | + | |
| 4 | +LL | fn f(a: A) -> A; |
| 5 | + | ^ |
| 6 | + | |
| 7 | +help: use a new generic type parameter, constrained by `A` |
| 8 | + | |
| 9 | +LL | fn f<T: A>(a: T) -> A; |
| 10 | + | ++++++ ~ |
| 11 | +help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference |
| 12 | + | |
| 13 | +LL | fn f(a: impl A) -> A; |
| 14 | + | ++++ |
| 15 | +help: alternatively, use a trait object to accept any type that implements `A`, accessing its methods at runtime using dynamic dispatch |
| 16 | + | |
| 17 | +LL | fn f(a: &dyn A) -> A; |
| 18 | + | ++++ |
| 19 | + |
| 20 | +error[E0782]: trait objects must include the `dyn` keyword |
| 21 | + --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:4:19 |
| 22 | + | |
| 23 | +LL | fn f(a: A) -> A; |
| 24 | + | ^ |
| 25 | + | |
| 26 | +help: use `impl A` to return an opaque type, as long as you return a single underlying type |
| 27 | + | |
| 28 | +LL | fn f(a: A) -> impl A; |
| 29 | + | ++++ |
| 30 | +help: alternatively, you can return an owned trait object |
| 31 | + | |
| 32 | +LL | fn f(a: A) -> Box<dyn A>; |
| 33 | + | +++++++ + |
| 34 | + |
| 35 | +error[E0782]: trait objects must include the `dyn` keyword |
| 36 | + --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:9:13 |
| 37 | + | |
| 38 | +LL | fn f(a: B) -> B; |
| 39 | + | ^ |
| 40 | + | |
| 41 | +help: use a new generic type parameter, constrained by `B` |
| 42 | + | |
| 43 | +LL | fn f<T: B>(a: T) -> B; |
| 44 | + | ++++++ ~ |
| 45 | +help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference |
| 46 | + | |
| 47 | +LL | fn f(a: impl B) -> B; |
| 48 | + | ++++ |
| 49 | +help: alternatively, use a trait object to accept any type that implements `B`, accessing its methods at runtime using dynamic dispatch |
| 50 | + | |
| 51 | +LL | fn f(a: &dyn B) -> B; |
| 52 | + | ++++ |
| 53 | + |
| 54 | +error[E0782]: trait objects must include the `dyn` keyword |
| 55 | + --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:9:19 |
| 56 | + | |
| 57 | +LL | fn f(a: B) -> B; |
| 58 | + | ^ |
| 59 | + | |
| 60 | +help: use `impl B` to return an opaque type, as long as you return a single underlying type |
| 61 | + | |
| 62 | +LL | fn f(a: B) -> impl B; |
| 63 | + | ++++ |
| 64 | +help: alternatively, you can return an owned trait object |
| 65 | + | |
| 66 | +LL | fn f(a: B) -> Box<dyn B>; |
| 67 | + | +++++++ + |
| 68 | + |
| 69 | +error[E0782]: trait objects must include the `dyn` keyword |
| 70 | + --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:14:20 |
| 71 | + | |
| 72 | +LL | fn f(&self, a: C) -> C; |
| 73 | + | ^ |
| 74 | + | |
| 75 | +help: use a new generic type parameter, constrained by `C` |
| 76 | + | |
| 77 | +LL | fn f<T: C>(&self, a: T) -> C; |
| 78 | + | ++++++ ~ |
| 79 | +help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference |
| 80 | + | |
| 81 | +LL | fn f(&self, a: impl C) -> C; |
| 82 | + | ++++ |
| 83 | +help: alternatively, use a trait object to accept any type that implements `C`, accessing its methods at runtime using dynamic dispatch |
| 84 | + | |
| 85 | +LL | fn f(&self, a: &dyn C) -> C; |
| 86 | + | ++++ |
| 87 | + |
| 88 | +error[E0782]: trait objects must include the `dyn` keyword |
| 89 | + --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:14:26 |
| 90 | + | |
| 91 | +LL | fn f(&self, a: C) -> C; |
| 92 | + | ^ |
| 93 | + | |
| 94 | +help: use `impl C` to return an opaque type, as long as you return a single underlying type |
| 95 | + | |
| 96 | +LL | fn f(&self, a: C) -> impl C; |
| 97 | + | ++++ |
| 98 | +help: alternatively, you can return an owned trait object |
| 99 | + | |
| 100 | +LL | fn f(&self, a: C) -> Box<dyn C>; |
| 101 | + | +++++++ + |
| 102 | + |
| 103 | +error: aborting due to 6 previous errors |
| 104 | + |
| 105 | +For more information about this error, try `rustc --explain E0782`. |
0 commit comments