我意识到这样做在Rust中不起作用,因为它抛出temp
Not Found错误,因为看起来#[cfg(not(feature = "my-feature"))]
左右的花括号创建了一个新的作用域,对吗?
fn main() {
#[cfg(not(feature = "my-feature"))] {
let temp: usize = 1;
}
let mut output = 0;
#[cfg(not(feature = "my-feature"))]
output = temp + 1;
println!("output: {:?}", output);
}
但是,在不引入新的作用域(即稍后重用现有变量)的情况下,在Rust中使用功能标志将多行包含起来的正确方法是什么呢?