2019-07-27 00:54:25 +03:00
|
|
|
//@ run-pass
|
|
|
|
|
2018-09-14 12:20:28 +02:00
|
|
|
#![allow(unused_imports)]
|
2017-03-17 14:10:00 -04:00
|
|
|
// 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-12 01:22:34 +08:00
|
|
|
|
2017-03-17 14:10:00 -04:00
|
|
|
use std::num::ParseIntError;
|
2016-08-11 17:06:39 +08:00
|
|
|
|
2017-03-17 14:10:00 -04:00
|
|
|
fn produce<T>() -> Result<&'static str, T> {
|
|
|
|
Ok("22")
|
2016-08-11 17:06:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2017-03-17 14:10:00 -04:00
|
|
|
let x: usize = produce()
|
|
|
|
.and_then(|x| x.parse())
|
|
|
|
.unwrap_or_else(|_| panic!());
|
|
|
|
println!("{}", x);
|
2016-08-11 17:06:39 +08:00
|
|
|
}
|