2021-04-17 13:56:07 -05:00
error[E0277]: `?` couldn't convert the error to `u8`
--> $DIR/bad-interconversion.rs:6:20
|
LL | fn result_to_result() -> Result<u64, u8> {
| --------------- expected `u8` because of this
LL | Ok(Err(123_i32)?)
Provide context when `?` can't be called because of `Result<_, E>`
When a method chain ending in `?` causes an E0277 because the
expression's `Result::Err` variant doesn't have a type that can be
converted to the `Result<_, E>` type parameter in the return type,
provide additional context of which parts of the chain can and can't
support the `?` operator.
```
error[E0277]: `?` couldn't convert the error to `String`
--> $DIR/question-mark-result-err-mismatch.rs:28:25
|
LL | fn bar() -> Result<(), String> {
| ------------------ expected `String` because of this
LL | let x = foo();
| ----- this can be annotated with `?` because it has type `Result<String, String>`
LL | let one = x
LL | .map(|s| ())
| ----------- this can be annotated with `?` because it has type `Result<(), String>`
LL | .map_err(|_| ())?;
| ---------------^ the trait `From<()>` is not implemented for `String`
| |
| this can't be annotated with `?` because it has type `Result<(), ()>`
|
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
= help: the following other types implement trait `From<T>`:
<String as From<char>>
<String as From<Box<str>>>
<String as From<Cow<'a, str>>>
<String as From<&str>>
<String as From<&mut str>>
<String as From<&String>>
= note: required for `Result<(), String>` to implement `FromResidual<Result<Infallible, ()>>`
```
Fix #72124.
2023-10-06 14:07:05 -05:00
| ------------^ the trait `From<i32>` is not implemented for `u8`
| |
| this can't be annotated with `?` because it has type `Result<_, i32>`
2021-04-17 13:56:07 -05:00
|
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
2022-03-26 21:02:07 -05:00
= help: the following other types implement trait `From<T>`:
2022-12-05 16:24:48 -06:00
<u8 as From<bool>>
2023-06-27 18:31:06 -05:00
<u8 as From<NonZeroU8>>
2022-08-15 15:31:37 -05:00
= note: required for `Result<u64, u8>` to implement `FromResidual<Result<Infallible, i32>>`
2021-04-17 13:56:07 -05:00
error[E0277]: the `?` operator can only be used on `Result`s, not `Option`s, in a function that returns `Result`
--> $DIR/bad-interconversion.rs:11:12
|
2022-09-01 14:52:39 -05:00
LL | fn option_to_result() -> Result<u64, String> {
| -------------------------------------------- this function returns a `Result`
LL | Some(3)?;
| ^ use `.ok_or(...)?` to provide an error compatible with `Result<u64, String>`
2021-04-17 13:56:07 -05:00
|
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `Result<u64, String>`
2022-04-24 21:59:23 -05:00
= help: the following other types implement trait `FromResidual<R>`:
<Result<T, F> as FromResidual<Yeet<E>>>
2023-06-27 18:31:06 -05:00
<Result<T, F> as FromResidual<Result<Infallible, E>>>
2021-04-17 13:56:07 -05:00
error[E0277]: the `?` operator can only be used on `Result`s in a function that returns `Result`
--> $DIR/bad-interconversion.rs:17:31
|
2022-09-01 14:52:39 -05:00
LL | fn control_flow_to_result() -> Result<u64, String> {
| -------------------------------------------------- this function returns a `Result`
LL | Ok(ControlFlow::Break(123)?)
| ^ this `?` produces `ControlFlow<{integer}, Infallible>`, which is incompatible with `Result<u64, String>`
2021-04-17 13:56:07 -05:00
|
= help: the trait `FromResidual<ControlFlow<{integer}, Infallible>>` is not implemented for `Result<u64, String>`
2022-04-24 21:59:23 -05:00
= help: the following other types implement trait `FromResidual<R>`:
<Result<T, F> as FromResidual<Yeet<E>>>
2023-06-27 18:31:06 -05:00
<Result<T, F> as FromResidual<Result<Infallible, E>>>
2021-04-17 13:56:07 -05:00
2021-05-23 01:47:12 -05:00
error[E0277]: the `?` operator can only be used on `Option`s, not `Result`s, in a function that returns `Option`
2021-04-17 13:56:07 -05:00
--> $DIR/bad-interconversion.rs:22:22
|
2022-09-01 14:52:39 -05:00
LL | fn result_to_option() -> Option<u16> {
| ------------------------------------ this function returns an `Option`
LL | Some(Err("hello")?)
| ^ use `.ok()?` if you want to discard the `Result<Infallible, &str>` error information
2021-04-17 13:56:07 -05:00
|
= help: the trait `FromResidual<Result<Infallible, &str>>` is not implemented for `Option<u16>`
2022-04-24 21:59:23 -05:00
= help: the following other types implement trait `FromResidual<R>`:
<Option<T> as FromResidual<Yeet<()>>>
<Option<T> as FromResidual>
2021-04-17 13:56:07 -05:00
error[E0277]: the `?` operator can only be used on `Option`s in a function that returns `Option`
--> $DIR/bad-interconversion.rs:27:33
|
2022-09-01 14:52:39 -05:00
LL | fn control_flow_to_option() -> Option<u64> {
| ------------------------------------------ this function returns an `Option`
LL | Some(ControlFlow::Break(123)?)
| ^ this `?` produces `ControlFlow<{integer}, Infallible>`, which is incompatible with `Option<u64>`
2021-04-17 13:56:07 -05:00
|
= help: the trait `FromResidual<ControlFlow<{integer}, Infallible>>` is not implemented for `Option<u64>`
2022-04-24 21:59:23 -05:00
= help: the following other types implement trait `FromResidual<R>`:
<Option<T> as FromResidual<Yeet<()>>>
<Option<T> as FromResidual>
2021-04-17 13:56:07 -05:00
2021-05-23 01:47:12 -05:00
error[E0277]: the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow`
2021-04-17 13:56:07 -05:00
--> $DIR/bad-interconversion.rs:32:39
|
2022-09-01 14:52:39 -05:00
LL | fn result_to_control_flow() -> ControlFlow<String> {
| -------------------------------------------------- this function returns a `ControlFlow`
LL | ControlFlow::Continue(Err("hello")?)
| ^ this `?` produces `Result<Infallible, &str>`, which is incompatible with `ControlFlow<String>`
2021-04-17 13:56:07 -05:00
|
= help: the trait `FromResidual<Result<Infallible, &str>>` is not implemented for `ControlFlow<String>`
2023-09-09 22:21:52 -05:00
= help: the trait `FromResidual<ControlFlow<String, Infallible>>` is implemented for `ControlFlow<String>`
2023-09-09 22:33:07 -05:00
= help: for that trait implementation, expected `ControlFlow<String, Infallible>`, found `Result<Infallible, &str>`
2021-04-17 13:56:07 -05:00
2021-05-23 01:47:12 -05:00
error[E0277]: the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow`
2021-04-17 13:56:07 -05:00
--> $DIR/bad-interconversion.rs:37:12
|
2022-09-01 14:52:39 -05:00
LL | fn option_to_control_flow() -> ControlFlow<u64> {
| ----------------------------------------------- this function returns a `ControlFlow`
LL | Some(3)?;
| ^ this `?` produces `Option<Infallible>`, which is incompatible with `ControlFlow<u64>`
2021-04-17 13:56:07 -05:00
|
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `ControlFlow<u64>`
2023-09-09 22:21:52 -05:00
= help: the trait `FromResidual<ControlFlow<u64, Infallible>>` is implemented for `ControlFlow<u64>`
2023-09-09 22:33:07 -05:00
= help: for that trait implementation, expected `ControlFlow<u64, Infallible>`, found `Option<Infallible>`
2021-04-17 13:56:07 -05:00
2021-05-23 01:47:12 -05:00
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)
2021-04-17 13:56:07 -05:00
--> $DIR/bad-interconversion.rs:43:29
|
2022-09-01 14:52:39 -05:00
LL | fn control_flow_to_control_flow() -> ControlFlow<i64> {
| ----------------------------------------------------- this function returns a `ControlFlow`
LL | ControlFlow::Break(4_u8)?;
| ^ this `?` produces `ControlFlow<u8, Infallible>`, which is incompatible with `ControlFlow<i64>`
2021-04-17 13:56:07 -05:00
|
= help: the trait `FromResidual<ControlFlow<u8, Infallible>>` is not implemented for `ControlFlow<i64>`
= note: unlike `Result`, there's no `From`-conversion performed for `ControlFlow`
2023-09-09 22:21:52 -05:00
= help: the trait `FromResidual<ControlFlow<i64, Infallible>>` is implemented for `ControlFlow<i64>`
2023-09-09 22:33:07 -05:00
= help: for that trait implementation, expected `i64`, found `u8`
2021-04-17 13:56:07 -05:00
error: aborting due to 8 previous errors
For more information about this error, try `rustc --explain E0277`.