|
1 | | -error[E0038]: the trait `A` cannot be made into an object |
2 | | - --> $DIR/avoid-ice-on-warning-3.rs:4:19 |
| 1 | +error[E0782]: trait objects must include the `dyn` keyword |
| 2 | + --> $DIR/avoid-ice-on-warning-3.rs:14:19 |
3 | 3 | | |
4 | | -LL | trait B { fn f(a: A) -> A; } |
5 | | - | ^ `A` cannot be made into an object |
| 4 | +LL | trait A { fn g(b: B) -> B; } |
| 5 | + | ^ |
6 | 6 | | |
7 | | -note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> |
8 | | - --> $DIR/avoid-ice-on-warning-3.rs:12:14 |
| 7 | + = note: `B` it is not object safe, so it can't be `dyn` |
| 8 | +help: use a new generic type parameter, constrained by `B` |
| 9 | + | |
| 10 | +LL | trait A { fn g<T: B>(b: T) -> B; } |
| 11 | + | ++++++ ~ |
| 12 | +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 |
| 13 | + | |
| 14 | +LL | trait A { fn g(b: impl B) -> B; } |
| 15 | + | ++++ |
| 16 | + |
| 17 | +error[E0782]: trait objects must include the `dyn` keyword |
| 18 | + --> $DIR/avoid-ice-on-warning-3.rs:14:25 |
9 | 19 | | |
10 | 20 | LL | trait A { fn g(b: B) -> B; } |
11 | | - | - ^ ...because associated function `g` has no `self` parameter |
12 | | - | | |
13 | | - | this trait cannot be made into an object... |
14 | | -help: consider turning `g` into a method by giving it a `&self` argument |
| 21 | + | ^ |
15 | 22 | | |
16 | | -LL | trait A { fn g(&self, b: B) -> B; } |
17 | | - | ++++++ |
18 | | -help: alternatively, consider constraining `g` so it does not apply to trait objects |
| 23 | +help: `B` is not object safe, use `impl B` to return an opaque type, as long as you return a single underlying type |
19 | 24 | | |
20 | | -LL | trait A { fn g(b: B) -> B where Self: Sized; } |
21 | | - | +++++++++++++++++ |
| 25 | +LL | trait A { fn g(b: B) -> impl B; } |
| 26 | + | ++++ |
22 | 27 |
|
23 | | -error[E0038]: the trait `B` cannot be made into an object |
24 | | - --> $DIR/avoid-ice-on-warning-3.rs:12:19 |
| 28 | +error[E0782]: trait objects must include the `dyn` keyword |
| 29 | + --> $DIR/avoid-ice-on-warning-3.rs:4:19 |
25 | 30 | | |
26 | | -LL | trait A { fn g(b: B) -> B; } |
27 | | - | ^ `B` cannot be made into an object |
| 31 | +LL | trait B { fn f(a: A) -> A; } |
| 32 | + | ^ |
28 | 33 | | |
29 | | -note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> |
30 | | - --> $DIR/avoid-ice-on-warning-3.rs:4:14 |
| 34 | + = note: `A` it is not object safe, so it can't be `dyn` |
| 35 | +help: use a new generic type parameter, constrained by `A` |
| 36 | + | |
| 37 | +LL | trait B { fn f<T: A>(a: T) -> A; } |
| 38 | + | ++++++ ~ |
| 39 | +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 |
| 40 | + | |
| 41 | +LL | trait B { fn f(a: impl A) -> A; } |
| 42 | + | ++++ |
| 43 | + |
| 44 | +error[E0782]: trait objects must include the `dyn` keyword |
| 45 | + --> $DIR/avoid-ice-on-warning-3.rs:4:25 |
31 | 46 | | |
32 | 47 | LL | trait B { fn f(a: A) -> A; } |
33 | | - | - ^ ...because associated function `f` has no `self` parameter |
34 | | - | | |
35 | | - | this trait cannot be made into an object... |
36 | | -help: consider turning `f` into a method by giving it a `&self` argument |
| 48 | + | ^ |
37 | 49 | | |
38 | | -LL | trait B { fn f(&self, a: A) -> A; } |
39 | | - | ++++++ |
40 | | -help: alternatively, consider constraining `f` so it does not apply to trait objects |
| 50 | +help: `A` is not object safe, use `impl A` to return an opaque type, as long as you return a single underlying type |
41 | 51 | | |
42 | | -LL | trait B { fn f(a: A) -> A where Self: Sized; } |
43 | | - | +++++++++++++++++ |
| 52 | +LL | trait B { fn f(a: A) -> impl A; } |
| 53 | + | ++++ |
44 | 54 |
|
45 | | -error: aborting due to 2 previous errors |
| 55 | +error: aborting due to 4 previous errors |
46 | 56 |
|
47 | | -For more information about this error, try `rustc --explain E0038`. |
| 57 | +For more information about this error, try `rustc --explain E0782`. |
0 commit comments