summaryrefslogtreecommitdiffstats
path: root/src/test/ui/try-block/try-block-bad-type.rs
blob: 30ae96763c0e291d5d45d3baa18dec91b78d2949 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// compile-flags: --edition 2018

#![feature(try_blocks)]

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

    let res: Result<i32, i32> = try {
        "" //~ ERROR type mismatch
    };

    let res: Result<i32, i32> = try { }; //~ ERROR type mismatch

    let res: () = try { };
    //~^ ERROR a `try` block must return `Result` or `Option`

    let res: i32 = try { 5 }; //~ ERROR a `try` block must return `Result` or `Option`
}