mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-25 14:13:38 +00:00
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 <ijackson@chiark.greenend.org.uk>
This commit is contained in:
parent
ee88f46bb5
commit
8ae05dfdf6
@ -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
|
||||
};
|
||||
|
@ -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`
|
||||
|
Loading…
Reference in New Issue
Block a user