rust/tests/ui/diverging-fallback-method-chain.rs

21 lines
497 B
Rust
Raw Normal View History

//@ run-pass
#![allow(unused_imports)]
// Test a regression found when building compiler. The `produce()`
// error type `T` winds up getting unified with result of `x.parse()`;
// the type of the closure given to `unwrap_or_else` needs to be
// inferred to `usize`.
2016-08-11 17:22:34 +00:00
use std::num::ParseIntError;
2016-08-11 09:06:39 +00:00
fn produce<T>() -> Result<&'static str, T> {
Ok("22")
2016-08-11 09:06:39 +00:00
}
fn main() {
let x: usize = produce()
.and_then(|x| x.parse())
.unwrap_or_else(|_| panic!());
println!("{}", x);
2016-08-11 09:06:39 +00:00
}