Skip to content

Commit

Permalink
Rollup merge of rust-lang#82233 - ijackson:try-block-type-test, r=Mar…
Browse files Browse the repository at this point in the history
…k-Simulacrum

try-back-block-type test: Use TryFromSliceError for From test

Using `i32` is rather fragile because it has many implementations.  Recently in an early draft of another MR (rust-lang#82228) I did something that introduced a new `i32 as From<something>` impl and this test broke.

TryFromSliceError is nice because it doesn't seem likely to grow new conversions.  We still have one conversion, from Infallible.

My other MR is going to be reworked and won't need this any more but having done it I thought I would submit it rather than just throw it away.  Sorry for the tiny MR.
  • Loading branch information
JohnTitor authored Feb 21, 2021
2 parents 20d99b2 + 8ae05df commit 9685a5e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/test/ui/try-block/try-block-bad-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![feature(try_blocks)]

pub fn main() {
let res: Result<u32, i32> = try {
let res: Result<u32, std::array::TryFromSliceError> = try {
Err("")?; //~ ERROR `?` couldn't convert the error
5
};
Expand Down
10 changes: 3 additions & 7 deletions src/test/ui/try-block/try-block-bad-type.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
error[E0277]: `?` couldn't convert the error to `i32`
error[E0277]: `?` couldn't convert the error to `TryFromSliceError`
--> $DIR/try-block-bad-type.rs:7:16
|
LL | Err("")?;
| ^ the trait `From<&str>` is not implemented for `i32`
| ^ the trait `From<&str>` is not implemented for `TryFromSliceError`
|
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
= help: the following implementations were found:
<i32 as From<NonZeroI32>>
<i32 as From<bool>>
<i32 as From<i16>>
<i32 as From<i8>>
and 2 others
<TryFromSliceError as From<Infallible>>
= note: required by `from`

error[E0271]: type mismatch resolving `<Result<i32, i32> as Try>::Ok == &str`
Expand Down

0 comments on commit 9685a5e

Please sign in to comment.