fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
6.0 KiB106 linesraw
1error[E0277]: `?` couldn't convert the error to `u8`
2  --> $DIR/bad-interconversion.rs:6:20
3   |
4LL | fn result_to_result() -> Result<u64, u8> {
5   |                          --------------- expected `u8` because of this
6LL |     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<bool>>
12             <u8 as From<NonZeroU8>>
13   = note: required for `Result<u64, u8>` to implement `FromResidual<Result<Infallible, i32>>`
14
15error[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   |
18LL | fn option_to_result() -> Result<u64, String> {
19   | -------------------------------------------- this function returns a `Result`
20LL |     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<Yeet<E>>>
26             <Result<T, F> as FromResidual<Result<Infallible, E>>>
27
28error[E0277]: the `?` operator can only be used on `Result`s in a function that returns `Result`
29  --> $DIR/bad-interconversion.rs:17:31
30   |
31LL | fn control_flow_to_result() -> Result<u64, String> {
32   | -------------------------------------------------- this function returns a `Result`
33LL |     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<Yeet<E>>>
39             <Result<T, F> as FromResidual<Result<Infallible, E>>>
40
41error[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   |
44LL | fn result_to_option() -> Option<u16> {
45   | ------------------------------------ this function returns an `Option`
46LL |     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
54error[E0277]: the `?` operator can only be used on `Option`s in a function that returns `Option`
55  --> $DIR/bad-interconversion.rs:27:33
56   |
57LL | fn control_flow_to_option() -> Option<u64> {
58   | ------------------------------------------ this function returns an `Option`
59LL |     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
67error[E0277]: the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow`
68  --> $DIR/bad-interconversion.rs:32:39
69   |
70LL | fn result_to_control_flow() -> ControlFlow<String> {
71   | -------------------------------------------------- this function returns a `ControlFlow`
72LL |     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<ControlFlow<String, Infallible>>` is implemented for `ControlFlow<String>`
77   = help: for that trait implementation, expected `ControlFlow<String, Infallible>`, found `Result<Infallible, &str>`
78
79error[E0277]: the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow`
80  --> $DIR/bad-interconversion.rs:37:12
81   |
82LL | fn option_to_control_flow() -> ControlFlow<u64> {
83   | ----------------------------------------------- this function returns a `ControlFlow`
84LL |     Some(3)?;
85   |            ^ this `?` produces `Option<Infallible>`, which is incompatible with `ControlFlow<u64>`
86   |
87   = help: the trait `FromResidual<Option<Infallible>>` is not implemented for `ControlFlow<u64>`
88   = help: the trait `FromResidual<ControlFlow<u64, Infallible>>` is implemented for `ControlFlow<u64>`
89   = help: for that trait implementation, expected `ControlFlow<u64, Infallible>`, found `Option<Infallible>`
90
91error[E0277]: the `?` operator in a function that returns `ControlFlow<B, _>` can only be used on other `ControlFlow<B, _>`s (with the same Break type)
92  --> $DIR/bad-interconversion.rs:43:29
93   |
94LL | fn control_flow_to_control_flow() -> ControlFlow<i64> {
95   | ----------------------------------------------------- this function returns a `ControlFlow`
96LL |     ControlFlow::Break(4_u8)?;
97   |                             ^ this `?` produces `ControlFlow<u8, Infallible>`, which is incompatible with `ControlFlow<i64>`
98   |
99   = help: the trait `FromResidual<ControlFlow<u8, Infallible>>` is not implemented for `ControlFlow<i64>`
100   = note: unlike `Result`, there's no `From`-conversion performed for `ControlFlow`
101   = help: the trait `FromResidual<ControlFlow<i64, Infallible>>` is implemented for `ControlFlow<i64>`
102   = help: for that trait implementation, expected `i64`, found `u8`
103
104error: aborting due to 8 previous errors
105
106For more information about this error, try `rustc --explain E0277`.