Rust 1.74.0 发布

Rust 1.74.0 稳定版已正式发布,主要带来以下变化:

通过 Cargo 进行 Lint 配置

正如 RFC 3389 所提议,Cargo.tomlmanifest 现在支持一个[lints]表来配置来自编译器和其他工具的 lints 的报告级别(禁止、拒绝、警告、允许)。因此,不要使用-F/-D/-W/-A设置 RUSTFLAGS(这会影响整个构建过程),或者使用 crate-level 的属性,例如:

#![forbid(unsafe_code)]
#![deny(clippy::enum_glob_use)]

现在可以将这些写入 package manifest 中以供 Cargo 处理:

[lints.rust]
unsafe_code = "forbid"

[lints.clippy]
enum_glob_use = "deny"

这些也可以在[workspace.lints]表中配置,然后像许多其他工作区设置一样由[lints] workspace = true继承。在决定哪些 crates 需要重建时,Cargo 还将跟踪这些设置的更改。

有关详细信息,可参阅 Cargo 参考手册中的lintsworkspace.lints部分。

Cargo Registry Authentication

此版本中还包含两个相关的 Cargo 功能:credential providers 和 authenticated private registries。

Credential providers 允许配置 Cargo 如何获取注册表的凭证。Built-in providers 用于 Linux、macOS 和 Windows 上特定于操作系统的安全秘密存储。此外,可以编写自定义 providers 来支持存储或生成令牌的任意方法。使用安全的 credential provider 可以降低注册表令牌泄漏的风险。

Registries 现在可以选择要求对所有操作进行身份验证,而不仅仅是发布。这使得 private Cargo registries 能够提供更安全的 crates 托管。使用 private registries 需要配置 credential provider。

有关更多信息,可参阅 Cargo 文档

Projections in opaque return types

有关返回“return type cannot contain a projection or Self that references lifetimes from a parent scope”错误信息的问题现在已经解决。编译器现在允许在 opaque return types 中提及Self和关联类型,例如async fn-> impl Trait。即使你对"projection"之类的术语一无所知,这种功能也能让 Rust 更接近你所期望的工作方式。

不过该功能目前有一个不稳定的 feature gate,因为它的实现最初没有正确处理 captured lifetimes。有关更多技术细节,可参阅 stabilization pull request。示例:

struct Wrapper<'a, T>(&'a T);

// Opaque return types that mention `Self`:
impl Wrapper<'_, ()> {
    async fn async_fn() -> Self { /* ... */ }
    fn impl_trait() -> impl Iterator<Item = Self> { /* ... */ }
}

trait Trait<'a> {
    type Assoc;
    fn new() -> Self::Assoc;
}
impl Trait<'_> for () {
    type Assoc = ();
    fn new() {}
}

// Opaque return types that mention an associated type:
impl<'a, T: Trait<'a>> Wrapper<'a, T> {
    async fn mk_assoc() -> T::Assoc { /* ... */ }
    fn a_few_assocs() -> impl Iterator<Item = T::Assoc> { /* ... */ }
}

Stabilized APIs

这些 API 现在在 const contexts 中是稳定的:

兼容性说明

  • 正如之前所宣布的,Rust 1.74 提高了对 Apple 平台的要求。现在最低版本是:
    • macOS:10.12 Sierra(2016 年首次发布)
    • iOS:10(2016 年首次发布)、
    • tvOS:10(2016 年首次发布)

其他变化

查看 RustCargo 和 Clippy 中发生的所有变化。

详情可查看官方公告

猜你喜欢

转载自www.oschina.net/news/266875/rust-1-74-0-released