在可变借用编译后无错误地借用不变

时间:2021-06-14 21:50:28

标签: rust

我正在阅读旧的 Rust 文档(Rust 1.3 附带的文档)并找到了 this example。为了阅读方便,我也在这里引用了这个例子:

fn main() {
    let mut x = 5;

    let y = &mut x;

    *y += 1;

    println!("{}", x);
}

它说如果我尝试构建它,它会抛出一个错误:

error: cannot borrow `x` as immutable because it is also borrowed as mutable
    println!("{}", x);
                   ^

但是我可以编译并运行它而没有任何错误。是否有任何主要版本迁移消除了这种错误消息?

0 个答案:

没有答案