]> git.lizzy.rs Git - rust.git/blob - src/test/ui/try-trait/bad-interconversion.stderr
Auto merge of #105229 - saethlin:zst-writes-to-unions, r=oli-obk
[rust.git] / src / test / ui / try-trait / bad-interconversion.stderr
1 error[E0277]: `?` couldn't convert the error to `u8`
2   --> $DIR/bad-interconversion.rs:6:20
3    |
4 LL | fn result_to_result() -> Result<u64, u8> {
5    |                          --------------- expected `u8` because of this
6 LL |     Ok(Err(123_i32)?)
7    |                    ^ the trait `From<i32>` is not implemented for `u8`
8    |
9    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
10    = help: the following other types implement trait `From<T>`:
11              <u8 as From<NonZeroU8>>
12              <u8 as From<bool>>
13    = note: required for `Result<u64, u8>` to implement `FromResidual<Result<Infallible, i32>>`
14
15 error[E0277]: the `?` operator can only be used on `Result`s, not `Option`s, in a function that returns `Result`
16   --> $DIR/bad-interconversion.rs:11:12
17    |
18 LL | fn option_to_result() -> Result<u64, String> {
19    | -------------------------------------------- this function returns a `Result`
20 LL |     Some(3)?;
21    |            ^ use `.ok_or(...)?` to provide an error compatible with `Result<u64, String>`
22    |
23    = help: the trait `FromResidual<Option<Infallible>>` is not implemented for `Result<u64, String>`
24    = help: the following other types implement trait `FromResidual<R>`:
25              <Result<T, F> as FromResidual<Result<Infallible, E>>>
26              <Result<T, F> as FromResidual<Yeet<E>>>
27
28 error[E0277]: the `?` operator can only be used on `Result`s in a function that returns `Result`
29   --> $DIR/bad-interconversion.rs:17:31
30    |
31 LL | fn control_flow_to_result() -> Result<u64, String> {
32    | -------------------------------------------------- this function returns a `Result`
33 LL |     Ok(ControlFlow::Break(123)?)
34    |                               ^ this `?` produces `ControlFlow<{integer}, Infallible>`, which is incompatible with `Result<u64, String>`
35    |
36    = help: the trait `FromResidual<ControlFlow<{integer}, Infallible>>` is not implemented for `Result<u64, String>`
37    = help: the following other types implement trait `FromResidual<R>`:
38              <Result<T, F> as FromResidual<Result<Infallible, E>>>
39              <Result<T, F> as FromResidual<Yeet<E>>>
40
41 error[E0277]: the `?` operator can only be used on `Option`s, not `Result`s, in a function that returns `Option`
42   --> $DIR/bad-interconversion.rs:22:22
43    |
44 LL | fn result_to_option() -> Option<u16> {
45    | ------------------------------------ this function returns an `Option`
46 LL |     Some(Err("hello")?)
47    |                      ^ use `.ok()?` if you want to discard the `Result<Infallible, &str>` error information
48    |
49    = help: the trait `FromResidual<Result<Infallible, &str>>` is not implemented for `Option<u16>`
50    = help: the following other types implement trait `FromResidual<R>`:
51              <Option<T> as FromResidual<Yeet<()>>>
52              <Option<T> as FromResidual>
53
54 error[E0277]: the `?` operator can only be used on `Option`s in a function that returns `Option`
55   --> $DIR/bad-interconversion.rs:27:33
56    |
57 LL | fn control_flow_to_option() -> Option<u64> {
58    | ------------------------------------------ this function returns an `Option`
59 LL |     Some(ControlFlow::Break(123)?)
60    |                                 ^ this `?` produces `ControlFlow<{integer}, Infallible>`, which is incompatible with `Option<u64>`
61    |
62    = help: the trait `FromResidual<ControlFlow<{integer}, Infallible>>` is not implemented for `Option<u64>`
63    = help: the following other types implement trait `FromResidual<R>`:
64              <Option<T> as FromResidual<Yeet<()>>>
65              <Option<T> as FromResidual>
66
67 error[E0277]: the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow`
68   --> $DIR/bad-interconversion.rs:32:39
69    |
70 LL | fn result_to_control_flow() -> ControlFlow<String> {
71    | -------------------------------------------------- this function returns a `ControlFlow`
72 LL |     ControlFlow::Continue(Err("hello")?)
73    |                                       ^ this `?` produces `Result<Infallible, &str>`, which is incompatible with `ControlFlow<String>`
74    |
75    = help: the trait `FromResidual<Result<Infallible, &str>>` is not implemented for `ControlFlow<String>`
76    = help: the trait `FromResidual` is implemented for `ControlFlow<B, C>`
77
78 error[E0277]: the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow`
79   --> $DIR/bad-interconversion.rs:37:12
80    |
81 LL | fn option_to_control_flow() -> ControlFlow<u64> {
82    | ----------------------------------------------- this function returns a `ControlFlow`
83 LL |     Some(3)?;
84    |            ^ this `?` produces `Option<Infallible>`, which is incompatible with `ControlFlow<u64>`
85    |
86    = help: the trait `FromResidual<Option<Infallible>>` is not implemented for `ControlFlow<u64>`
87    = help: the trait `FromResidual` is implemented for `ControlFlow<B, C>`
88
89 error[E0277]: the `?` operator in a function that returns `ControlFlow<B, _>` can only be used on other `ControlFlow<B, _>`s (with the same Break type)
90   --> $DIR/bad-interconversion.rs:43:29
91    |
92 LL | fn control_flow_to_control_flow() -> ControlFlow<i64> {
93    | ----------------------------------------------------- this function returns a `ControlFlow`
94 LL |     ControlFlow::Break(4_u8)?;
95    |                             ^ this `?` produces `ControlFlow<u8, Infallible>`, which is incompatible with `ControlFlow<i64>`
96    |
97    = help: the trait `FromResidual<ControlFlow<u8, Infallible>>` is not implemented for `ControlFlow<i64>`
98    = note: unlike `Result`, there's no `From`-conversion performed for `ControlFlow`
99    = help: the trait `FromResidual` is implemented for `ControlFlow<B, C>`
100
101 error: aborting due to 8 previous errors
102
103 For more information about this error, try `rustc --explain E0277`.