blob: 8f549b7d9d686cebc00a09f480a1a2e6400f3b30 [file] [log] [blame]
//! 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);
}