Open
Description
The following code only compiles with try!
, not when using the ?
-syntax instead:
#![feature(question_mark)]
fn foo() -> Result<Vec<u32>, std::num::ParseIntError> {
let s = &["42", "1337"];
let parsed: Vec<u32> = try!(s.iter().map(|str| {
let val = str.parse::<u32>()?;
Ok(val + 1)
}).collect());
Ok(parsed)
}
fn main() {
println!("{:?}", foo());
}
Replacing the single try!
in function foo
with its ?
equivalent produces the following error:
error[E0284]: type annotations required: cannot resolve `<_ as std::ops::Carrier>::Success == _`
--> <anon>:6:28
|
6 | let parsed: Vec<u32> = s.iter().map(|str| {
| ^
error: aborting due to previous error
Example on playground: https://is.gd/CPUV0f (replace try!
with ?
to see the error)
Rustc version: rustc 1.13.0-nightly (acd3f79 2016-08-28)
Note: @KiChjang mentioned on IRC that using turbofish on the collect call, .collect::<Result<_,_>>()
, makes the ?
version compile again.