]> git.lizzy.rs Git - rust.git/blob - tests/ui/mismatched_types/suggest-boxed-trait-objects-instead-of-impl-trait.stderr
Auto merge of #106627 - Ezrashaw:no-e0711-without-staged-api, r=Mark-Simulacrum
[rust.git] / tests / ui / mismatched_types / suggest-boxed-trait-objects-instead-of-impl-trait.stderr
1 error[E0308]: `if` and `else` have incompatible types
2   --> $DIR/suggest-boxed-trait-objects-instead-of-impl-trait.rs:17:9
3    |
4 LL | /     if true {
5 LL | |         S
6    | |         - expected because of this
7 LL | |     } else {
8 LL | |         Y
9    | |         ^ expected struct `S`, found struct `Y`
10 LL | |     }
11    | |_____- `if` and `else` have incompatible types
12    |
13 help: you could change the return type to be a boxed trait object
14    |
15 LL | fn foo() -> Box<dyn Trait> {
16    |             ~~~~~~~      +
17 help: if you change the return type to expect trait objects, box the returned expressions
18    |
19 LL ~         Box::new(S)
20 LL |     } else {
21 LL ~         Box::new(Y)
22    |
23
24 error[E0308]: `match` arms have incompatible types
25   --> $DIR/suggest-boxed-trait-objects-instead-of-impl-trait.rs:24:18
26    |
27 LL | /     match true {
28 LL | |         true => S,
29    | |                 - this is found to be of type `S`
30 LL | |         false => Y,
31    | |                  ^ expected struct `S`, found struct `Y`
32 LL | |     }
33    | |_____- `match` arms have incompatible types
34    |
35 help: you could change the return type to be a boxed trait object
36    |
37 LL | fn bar() -> Box<dyn Trait> {
38    |             ~~~~~~~      +
39 help: if you change the return type to expect trait objects, box the returned expressions
40    |
41 LL ~         true => Box::new(S),
42 LL ~         false => Box::new(Y),
43    |
44
45 error: aborting due to 2 previous errors
46
47 For more information about this error, try `rustc --explain E0308`.