]> git.lizzy.rs Git - rust.git/blob - src/test/ui/impl-trait/object-unsafe-trait-in-return-position-impl-trait.stderr
9abebeff95a87a97b05974e01b8e2cd253fbbf7d
[rust.git] / src / test / ui / impl-trait / object-unsafe-trait-in-return-position-impl-trait.stderr
1 error[E0308]: mismatched types
2   --> $DIR/object-unsafe-trait-in-return-position-impl-trait.rs:36:5
3    |
4 LL | fn can() -> impl NotObjectSafe {
5    |             ------------------ expected because this return type...
6 LL |     if true {
7 LL |         return A;
8    |                - ...is found to be `A` here
9 LL |     }
10 LL |     B
11    |     ^ expected struct `A`, found struct `B`
12    |
13    = note: to return `impl Trait`, all returned values must be of the same type
14    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
15    = help: if the trait `NotObjectSafe` were object safe, you could return a boxed trait object
16    = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
17    = help: alternatively, create a new `enum` with a variant for each returned type
18
19 error[E0308]: mismatched types
20   --> $DIR/object-unsafe-trait-in-return-position-impl-trait.rs:43:5
21    |
22 LL | fn cat() -> impl ObjectSafe {
23    |             --------------- expected because this return type...
24 LL |     if true {
25 LL |         return A;
26    |                - ...is found to be `A` here
27 LL |     }
28 LL |     B
29    |     ^ expected struct `A`, found struct `B`
30    |
31    = note: to return `impl Trait`, all returned values must be of the same type
32    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
33    = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
34    = help: alternatively, create a new `enum` with a variant for each returned type
35 help: you could change the return type to be a boxed trait object
36    |
37 LL | fn cat() -> Box<dyn ObjectSafe> {
38    |             ^^^^^^^           ^
39
40 error: aborting due to 2 previous errors
41
42 For more information about this error, try `rustc --explain E0308`.