编译器:rustc 1.71.0-nightly (c609da59d 2023-04-18)
我尝试了夜版的#![feature(try_blocks)],使用了以下代码:
但编译器声称
如果我尝试使用
看起来
这是因为这个特性不稳定,还是我漏掉了什么?
我尝试了夜版的#![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>
之外还可能是其他类型吗?