Rust 1.26.2 发布

2018年6月5日 · Rust 核心团队

Rust 团队很高兴地宣布 Rust 的新版本 1.26.2。Rust 是一种专注于安全性、速度和并发性的系统编程语言。

如果您通过 rustup 安装了之前的 Rust 版本,那么获取 Rust 1.26.2 非常简单,只需执行以下命令:

$ rustup update stable

如果您还没有安装 rustup,可以从我们网站上的相应页面获取 rustup,并查看 GitHub 上 1.26.2 的详细发行说明

1.26.2 稳定版的新特性

此补丁版本修复了 match 表达式的借用检查器验证中的一个错误。此错误是在 1.26.0 版本中引入的,当时 match 人体工程学得到了稳定。具体来说,它允许代码同时对 bar 路径进行两次可变借用。

let mut foo = Some("foo".to_string());
let bar = &mut foo;
match bar {
    Some(baz) => {
        bar.take(); // Should not be permitted, as baz has a unique reference to the bar pointer.
    },
    None => unreachable!(),
}

1.26.2 将拒绝上述代码,并显示以下错误消息:

error[E0499]: cannot borrow `*bar` as mutable more than once at a time
 --> src/main.rs:6:9
  |
5 |     Some(baz) => {
  |          --- first mutable borrow occurs here
6 |         bar.take(); // Should not be permitted, as baz has a ...
  |         ^^^ second mutable borrow occurs here
...
9 | }
  | - first borrow ends here

error: aborting due to previous error

核心团队决定发布一个点版本,以最大程度地减少 Rust 编译器中存在此错误的时间窗口。