Rust 1.84.0 发布
01-13 09:22 来源:oschina 阅读(121)

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


Cargo 会考虑 Rust 版本来选择依赖版本


1.84.0 稳定了最低支持 Rust 版本(MSRV)感知解析器,该解析器会优先选择与项目声明的 MSRV 兼容的依赖版本。有了 MSRV 感知版本选择功能,维护者无需为每个依赖关系手动选择旧版本,从而减少了支持旧工具链的工作量。


可以通过.cargo/config.toml启用 MSRV 感知解析器:

[resolver]

incompatible-rust-versions = "fallback"

然后在添加依赖项时:


$ cargo add clap
    Updating crates.io index
warning: ignoring clap@4.5.23 (which requires rustc 1.74) to maintain demo's rust-version of 1.60
      Adding clap v4.0.32 to dependencies
    Updating crates.io index
     Locking 33 packages to latest Rust 1.60 compatible versions
      Adding clap v4.0.32 (available: v4.5.23, requires Rust 1.74)

在 CI 中验证最新依赖项时,可以覆盖此项:

$ CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS=allow cargo update
    Updating crates.io index
     Locking 12 packages to latest compatible versions
    Updating clap v4.0.32 -> v4.5.23

也可以通过在 Cargo.toml 清单文件中设置 package.resolver = "3"来启用,但这要求将 MSRV 升级到 1.84。对于使用 2024 版(将在 1.85 版中稳定)的项目,新的解析器将默认启用。


可参阅文档以了解更多注意事项。


开始迁移到新的 trait solver

https://www.zuocode.com

Rust 编译器正在向新的 trait solver 迁移。下一代 trait solver 是 Rust 类型系统核心组件的重新实现。在 1.84 中,新的求解器用于 trait impls 的一致性。从高层次上讲,连贯性负责确保在考虑其他 crate 中尚未编写或不可见代码的情况下,最多只有一个 trait 实现适用于给定类型。


此次 stabilization 修复了旧实现中的一些主要是理论正确性的问题,从而解决了以前未报告的潜在的 “conflicting implementations of trait ...” 错误。更多详细信息,可参阅之前的博客文章和 stabilization report。


Strict provenance APIs


在此版本中,Rust 添加了一组 API,在许多情况下可以替代整数指针转换的使用,从而避免此类转换固有的歧义。特别是,现在可以实现使用对齐指针的最低有效位来存储额外信息的模式,而无需将指针转换为整数或返回。这使得代码更易于推理,更易于编译器分析,并且还有利于 Miri 等工具和 CHERI 等旨在检测和诊断指针滥用的架构 。


稳定的 API


Ipv6Addr::is_unique_local

Ipv6Addr::is_unicast_link_local

core::ptr::with_exposed_provenance

core::ptr::with_exposed_provenance_mut

<ptr>::addr

<ptr>::expose_provenance

<ptr>::with_addr

<ptr>::map_addr

<int>::isqrt

<int>::checked_isqrt

<uint>::isqrt

NonZero::isqrt

core::ptr::without_provenance

core::ptr::without_provenance_mut

core::ptr::dangling

core::ptr::dangling_mut

Pin::as_deref_mut

这些 API 现在在 const 上下文中是稳定的


AtomicBool::from_ptr

AtomicPtr::from_ptr

AtomicU8::from_ptr

AtomicU16::from_ptr

AtomicU32::from_ptr

AtomicU64::from_ptr

AtomicUsize::from_ptr

AtomicI8::from_ptr

AtomicI16::from_ptr

AtomicI32::from_ptr

AtomicI64::from_ptr

AtomicIsize::from_ptr

<ptr>::is_null

<ptr>::as_ref

<ptr>::as_mut

Pin::new

Pin::new_unchecked

Pin::get_ref

Pin::into_ref

Pin::get_mut

Pin::get_unchecked_mut

Pin::static_ref

Pin::static_mut


https://www.zuocode.com