about summary refs log tree commit diff
path: root/tests/ui/typeck/inference-method-chain-diverging-fallback.rs
blob: 8f549b7d9d686cebc00a09f480a1a2e6400f3b30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//! Test type inference in method chains with diverging fallback.
//! Verifies that closure type in `unwrap_or_else` is properly inferred
//! when chained with other combinators and contains a diverging path.

//@ run-pass

fn produce<T>() -> Result<&'static str, T> {
    Ok("22")
}

fn main() {
    // The closure's error type `T` must unify with `ParseIntError`,
    // while the success type must be `usize` (from parse())
    let x: usize = produce()
        .and_then(|x| x.parse::<usize>()) // Explicit turbofish for clarity
        .unwrap_or_else(|_| panic!()); // Diverging fallback

    assert_eq!(x, 22);
}