diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2021-05-22 23:47:12 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2021-05-23 07:18:02 -0700 |
| commit | 8be67998a1f488b386d2982b3ddeec65099ab14c (patch) | |
| tree | 5d57b987da96a4809f9a3bfa9c3ca11b22030806 /src/test | |
| parent | 3bcaeb0bf9e1c29d18abc32928fd2f23d1bed0bd (diff) | |
| download | rust-8be67998a1f488b386d2982b3ddeec65099ab14c.tar.gz rust-8be67998a1f488b386d2982b3ddeec65099ab14c.zip | |
Extend rustc_on_implemented to improve a ?-on-ControlFlow error message
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/try-trait/bad-interconversion.rs | 8 | ||||
| -rw-r--r-- | src/test/ui/try-trait/bad-interconversion.stderr | 12 | ||||
| -rw-r--r-- | src/test/ui/try-trait/option-to-result.stderr | 4 |
3 files changed, 11 insertions, 13 deletions
diff --git a/src/test/ui/try-trait/bad-interconversion.rs b/src/test/ui/try-trait/bad-interconversion.rs index 87585822f57..385f5510fb4 100644 --- a/src/test/ui/try-trait/bad-interconversion.rs +++ b/src/test/ui/try-trait/bad-interconversion.rs @@ -20,7 +20,7 @@ fn control_flow_to_result() -> Result<u64, String> { fn result_to_option() -> Option<u16> { Some(Err("hello")?) - //~^ ERROR the `?` operator can only be used on `Option`s in a function that returns `Option` + //~^ ERROR the `?` operator can only be used on `Option`s, not `Result`s, in a function that returns `Option` } fn control_flow_to_option() -> Option<u64> { @@ -30,18 +30,18 @@ fn control_flow_to_option() -> Option<u64> { fn result_to_control_flow() -> ControlFlow<String> { ControlFlow::Continue(Err("hello")?) - //~^ ERROR the `?` operator can only be used on `ControlFlow<B, _>`s in a function that returns `ControlFlow<B, _>` + //~^ ERROR the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow` } fn option_to_control_flow() -> ControlFlow<u64> { Some(3)?; - //~^ ERROR the `?` operator can only be used on `ControlFlow<B, _>`s in a function that returns `ControlFlow<B, _>` + //~^ ERROR the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow` ControlFlow::Break(10) } fn control_flow_to_control_flow() -> ControlFlow<i64> { ControlFlow::Break(4_u8)?; - //~^ ERROR the `?` operator can only be used on `ControlFlow<B, _>`s in a function that returns `ControlFlow<B, _>` + //~^ ERROR the `?` operator in a function that returns `ControlFlow<B, _>` can only be used on other `ControlFlow<B, _>`s ControlFlow::Continue(()) } diff --git a/src/test/ui/try-trait/bad-interconversion.stderr b/src/test/ui/try-trait/bad-interconversion.stderr index e396256de22..f5b315c2519 100644 --- a/src/test/ui/try-trait/bad-interconversion.stderr +++ b/src/test/ui/try-trait/bad-interconversion.stderr @@ -40,12 +40,12 @@ LL | | } = help: the trait `FromResidual<ControlFlow<{integer}, Infallible>>` is not implemented for `Result<u64, String>` = note: required by `from_residual` -error[E0277]: the `?` operator can only be used on `Option`s in a function that returns `Option` +error[E0277]: the `?` operator can only be used on `Option`s, not `Result`s, in a function that returns `Option` --> $DIR/bad-interconversion.rs:22:22 | LL | / fn result_to_option() -> Option<u16> { LL | | Some(Err("hello")?) - | | ^ this `?` produces `Result<Infallible, &str>`, which is incompatible with `Option<u16>` + | | ^ use `.ok()?` if you want to discard the `Result<Infallible, &str>` error information LL | | LL | | } | |_- this function returns an `Option` @@ -66,7 +66,7 @@ LL | | } = help: the trait `FromResidual<ControlFlow<{integer}, Infallible>>` is not implemented for `Option<u64>` = note: required by `from_residual` -error[E0277]: the `?` operator can only be used on `ControlFlow<B, _>`s in a function that returns `ControlFlow<B, _>` +error[E0277]: the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow` --> $DIR/bad-interconversion.rs:32:39 | LL | / fn result_to_control_flow() -> ControlFlow<String> { @@ -77,10 +77,9 @@ LL | | } | |_- this function returns a `ControlFlow` | = help: the trait `FromResidual<Result<Infallible, &str>>` is not implemented for `ControlFlow<String>` - = note: unlike `Result`, there's no `From`-conversion performed for `ControlFlow` = note: required by `from_residual` -error[E0277]: the `?` operator can only be used on `ControlFlow<B, _>`s in a function that returns `ControlFlow<B, _>` +error[E0277]: the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow` --> $DIR/bad-interconversion.rs:37:12 | LL | / fn option_to_control_flow() -> ControlFlow<u64> { @@ -92,10 +91,9 @@ LL | | } | |_- this function returns a `ControlFlow` | = help: the trait `FromResidual<Option<Infallible>>` is not implemented for `ControlFlow<u64>` - = note: unlike `Result`, there's no `From`-conversion performed for `ControlFlow` = note: required by `from_residual` -error[E0277]: the `?` operator can only be used on `ControlFlow<B, _>`s in a function that returns `ControlFlow<B, _>` +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) --> $DIR/bad-interconversion.rs:43:29 | LL | / fn control_flow_to_control_flow() -> ControlFlow<i64> { diff --git a/src/test/ui/try-trait/option-to-result.stderr b/src/test/ui/try-trait/option-to-result.stderr index 92087c2aba2..9f7d80d4f23 100644 --- a/src/test/ui/try-trait/option-to-result.stderr +++ b/src/test/ui/try-trait/option-to-result.stderr @@ -12,13 +12,13 @@ LL | | } = help: the trait `FromResidual<Option<Infallible>>` is not implemented for `Result<(), ()>` = note: required by `from_residual` -error[E0277]: the `?` operator can only be used on `Option`s in a function that returns `Option` +error[E0277]: the `?` operator can only be used on `Option`s, not `Result`s, in a function that returns `Option` --> $DIR/option-to-result.rs:11:6 | LL | / fn test_option() -> Option<i32>{ LL | | let a:Result<i32, i32> = Ok(5); LL | | a?; - | | ^ this `?` produces `Result<Infallible, i32>`, which is incompatible with `Option<i32>` + | | ^ use `.ok()?` if you want to discard the `Result<Infallible, i32>` error information LL | | Some(5) LL | | } | |_- this function returns an `Option` |
