Skip to content

Commit 8ae05df

Browse files
committed
try-back-block-type test: Use TryFromSliceError for From test
Using `i32` is rather fragile because it has many implementations - and indeed I'm about to add one. TryFromSliceError is nice because it doesn't seem likely to grow new conversions. We still have one conversion, from Infallible. Signed-off-by: Ian Jackson <[email protected]>
1 parent ee88f46 commit 8ae05df

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/test/ui/try-block/try-block-bad-type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![feature(try_blocks)]
44

55
pub fn main() {
6-
let res: Result<u32, i32> = try {
6+
let res: Result<u32, std::array::TryFromSliceError> = try {
77
Err("")?; //~ ERROR `?` couldn't convert the error
88
5
99
};

src/test/ui/try-block/try-block-bad-type.stderr

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
error[E0277]: `?` couldn't convert the error to `i32`
1+
error[E0277]: `?` couldn't convert the error to `TryFromSliceError`
22
--> $DIR/try-block-bad-type.rs:7:16
33
|
44
LL | Err("")?;
5-
| ^ the trait `From<&str>` is not implemented for `i32`
5+
| ^ the trait `From<&str>` is not implemented for `TryFromSliceError`
66
|
77
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
88
= help: the following implementations were found:
9-
<i32 as From<NonZeroI32>>
10-
<i32 as From<bool>>
11-
<i32 as From<i16>>
12-
<i32 as From<i8>>
13-
and 2 others
9+
<TryFromSliceError as From<Infallible>>
1410
= note: required by `from`
1511

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

0 commit comments

Comments
 (0)