编译器:rustc 1.71.0-nightly (c609da59d 2023-04-18)
我试着每晚#![feature(try_blocks)]
次,用这个:
#![feature(try_blocks)]
fn test_try(input: Option<i32>) {
let output = try {
input?
};
println!("{:?}", output);
}
但是编译器声称output
需要类型注释.完整的错误信息在这里:
error[E0282]: type annotations needed
--> src/main.rs:3:9
|
3 | let output = try {
| ^^^^^^
|
help: consider giving `output` an explicit type
|
3 | let output: /* Type */ = try {
| ++++++++++++
如果我试了let output: Option<i32> = ...
次,一切都很好.
看起来output
应该是Option<i32>
,但编译器不能推断这一点.
是因为功能不稳定,还是我错过了什么?output
可以是Option<i32>
以外的任何其他类型吗?