Rust团队已经发布了Rust的新修正版本1.41.1。Rust是一种编程语言,它使每个人都可以创建可靠而高效的软件。
如果使用tools安装了旧版本的Rust rustup
,那么要升级到1.41.1版本,只需运行以下命令:
rustup update stable
如果尚未安装rustup
,则可以从我们网站的相应页面进行安装
稳定版1.41.1中包含什么
Rust 1.41.1专用于Rust 1.41.0中出现的两个关键回归:静态生命周期中的不正确和导致分段错误的错误编译。这些回归不会影响Rust的早期版本,我们建议Rust 1.41.0的用户尽快升级。自Rust 1.0以来'static
,Copy
存在与生存期和特征实现之间的交互有关的另一个问题,并且此版本也对此进行了修复。
static
元素验证失败
在Rust 1.41.0中,由于static
值的内部表示形式发生了一些变化,借用分析器意外地解决了一些错误的程序。特别是,借用分析器没有检查static
元素类型的正确性。这反过来,允许我们用一生短于临时分配值'static
的static
变量:
static mut MY_STATIC: &'static u8 = &0;
fn main() {
let my_temporary = 42;
unsafe {
MY_STATIC = &my_temporary;
}
}
在1.41.1中,此类代码将无法编译:
error[E0597]: `my_temporary` does not live long enough
--> src/main.rs:6:21
|
6 | MY_STATIC = &my_temporary;
| ------------^^^^^^^^^^^^^
| | |
| | borrowed value does not live long enough
| assignment requires that `my_temporary` is borrowed for `'static`
7 | }
8 | }
| - `my_temporary` dropped here while still borrowed
您可以在#69114和修复该错误的PR中了解更多有关此错误的信息。
Copy
终身实施'static
从Rust 1.0开始,以下错误程序已成功编译:
#[derive(Clone)]
struct Foo<'a>(&'a u32);
impl Copy for Foo<'static> {}
fn main() {
let temporary = 2;
let foo = (Foo(&temporary),);
drop(foo.0);
drop(foo.0);
}
对于Rust 1.41.1,已使用与上述相同的PR修复了此问题。现在,编译程序会产生以下错误:
error[E0597]: `temporary` does not live long enough
--> src/main.rs:7:20
|
7 | let foo = (Foo(&temporary),);
| ^^^^^^^^^^ borrowed value does not live long enough
8 | drop(foo.0);
| ----- copying this value requires that
| `temporary` is borrowed for `'static`
9 | drop(foo.0);
10 | }
| - `temporary` dropped here while still borrowed
- , Foo<'a>
, 'a
, Copy
, 'a: 'static
. temporary
'0
'static
, , Foo<'0>
Copy
, drop
.
, .
, Rust 1.41.0, . , , . , LLVM, LLVM 9 LLVM 10.
Rust 1.41.0 LLVM 9 Rust 1.41.1 , . : #69225.
1.41.1
, Rust 1.41.1. , !
Rust - .