Rust Knowledge Patch
Baseline: Rust through 1.84.x (2021 Edition); covers 1.84.0–1.97.0, Rust 2024 Edition, Cargo additions, and relevant point-release compatibility notes.
Reference index
| Reference | Topics | | --- | --- | | edition-2024.md | Edition migration, syntax, match ergonomics, temporary scope, unsafe requirements, resolver 3, doctests, rustfmt | | language-and-macros.md | Traits, opaque types, inference, patterns, macros, name resolution, lints, newly rejected code | | safety-ffi-and-low-level.md | Raw pointers, provenance, pinning, atomics, allocation, FFI, ABIs, intrinsics, inline assembly | | standard-library.md | Collections, iterators, ranges, I/O, paths, text, numerics, const stabilization, behavior contracts | | cargo.md | Configuration, builds, workspaces, publishing, lockfiles, registries, cache, metadata, environment variables | | targets-and-toolchains.md | Linkers, symbol mangling, WebAssembly, target tiers, platform baselines, LLVM, native linking | | docs-tests-and-formatting.md | Rustdoc, doctests, libtest, rustfmt, diagnostic path handling |
Apply this patch
- Identify the crate edition, MSRV, compilation targets, panic strategy, and whether Cargo or rustc is invoked directly.
- Check the breaking-change sections below before adopting new APIs.
- Read only the topic references relevant to the task; they hold the complete compatibility details and stable API inventory.
- Preserve an older MSRV unless the requested change intentionally raises it. New syntax, APIs, Cargo keys, and TOML 1.1 forms require the corresponding toolchain.
- For unsafe, FFI, linker, or custom-target work, validate the target-specific preconditions instead of relying on host behavior.
Breaking changes and migrations
Rust 2024 is a semantic migration
- Run
cargo fix --edition, then review every edit; several migrations insert syntax without proving safety or lifetime intent. - Declare foreign blocks as
unsafe extern, wrapno_mangle,export_name, andlink_sectionas unsafe attributes, and put unsafe operations inside explicit blocks even within anunsafe fn. - Replace references to
static mutwith synchronization or tightly scoped raw-pointer access. - Audit never-type fallback, return-position
impl Traitcapture, boxed-slice.into_iter(), match ergonomics,if letscrutinee temporaries, and tail-expression temporary destruction. - Review macro match order because 2024
exprfragments accept const blocks and_; useexpr_2021only when the old grammar is required. - Rename
genidentifiers or user#gen; separate guarded-string#tokens with whitespace. - Expect resolver 3 for 2024 packages, but configure it explicitly in a virtual workspace.
- Read edition-2024.md before changing a crate's edition.
Compiler acceptance changed
- Trait overlap uses the next-generation solver (1.84.0), so upgrades may reject previously accepted unsound impl sets or accept newly provable disjoint sets.
- Never-type fallback lints become deny-by-default in 1.92.0 when building the affected crate directly.
- Pattern capture, binding, and destruction order changed in several releases; code with visible destructor effects or partial moves needs focused tests.
- Macro expansions with trailing semicolons, missing fragment specifiers, invalid export attributes, unsupported ABI strings, and several formerly tolerated syntactic forms now warn or fail.
- Custom JSON target specifications require nightly options as of 1.95.0.
- WebAssembly unresolved symbols fail linking as of 1.96.0; declare intentional imports explicitly.
- Read language-and-macros.md and targets-and-toolchains.md during upgrade triage.
ABI, linking, and symbol behavior changed
wasm32-unknown-unknownswitched to the standards-compliant C ABI in 1.89.0; do not mix objects built under the old and new conventions.x86_64-unknown-linux-gnuuses LLD by default from 1.90.0; opt out with-Clinker-features=-lldonly for a confirmed incompatibility.- Linux
panic=abortbuilds retain unwind tables from 1.92.0 unless-C force-unwind-tables=nois set. - Stable rustc emits v0 Rust symbols by default from 1.97.0; update debuggers, profilers, and backtrace expectations.
- The layouts of types without an explicit representation remain non-contractual; 1.96.0 and 1.97.0 include observable layout corrections or changes.
- Read safety-ffi-and-low-level.md before altering FFI or unsafe code.
Pinning and pointer assumptions need review
pin!(&mut_value)no longer performs a dereference coercion in 1.97.0; make the intended pointee explicit.- Raw-reference formation through a raw pointer and to a union field is safe, but dereferencing the result still requires valid unsafe reasoning.
- Debug null-pointer checks are not soundness checks and disappear when debug assertions are disabled.
- Use exposed-provenance APIs rather than integer transmutation when reconstructing pointers.
Cargo workflows changed
- Cargo may automatically clean unused cache data from 1.88.0; disable it when old Cargo installations share entries that newer Cargo cannot observe.
cargo publish --workspacepublishes in dependency order but is not atomic (1.90.0).cargo publishno longer leaves a local.crate; usecargo packagewhen that artifact is required.- Published crates always include
Cargo.lock, whilecargo package --exclude-lockfileexplicitly omits it from a package archive. - Lockfile v4 is the default; declare the actual
package.rust-versionto preserve compatibility with Cargo older than 1.78. build.build-dir,resolver.lockfile-path, configurationinclude, target-specificrustdocflags, andbuild.warningssolve distinct build-layout and policy needs.- Use registry credential providers instead of command-line publish tokens.
- Read cargo.md before changing CI, packaging, registry, or workspace automation.
High-value language features
Traits and opaque types
- Trait-object upcasting to a supertrait is stable from 1.86.0 for references, smart pointers, and raw pointers with valid vtables.
- Trait return-position
impl Traitsupports preciseuse<...>capture from 1.87.0. - Associated types may repeat bounds from 1.92.0, and associated-item bounds now guide auto-trait and
Sizedreasoning.
trait Super {}
trait Sub: Super {}
fn upcast(value: &dyn Sub) -> &dyn Super {
value
}
trait Value {
fn value<'a>(&'a self) -> impl Sized + use<Self>;
}
Conditions, patterns, and configuration
- Edition 2024 supports
letchains inifandwhile; 1.95.0 addsif letmatch guards. cfg_select!chooses the first matching item or expression arm from 1.95.0.assert_matches!anddebug_assert_matches!provide pattern failures withDebugoutput from 1.96.0; import them explicitly.
match value {
Some(x) if let Ok(y) = compute(x) => use_pair(x, y),
_ => {}
}
Ranges and slices
array_windowsyields overlapping&[T; N]windows from 1.94.0.core::rangeintroduces copyable range values whose iterator types implement iteration; range syntax still constructs legacycore::opsranges.- Use
RangeBoundsin public APIs that should accept both range families.
use core::range::Range;
#[derive(Clone, Copy)]
struct Span(Range<usize>);
High-value library features
Multi-borrowing and extraction
- Slices and
HashMapsupport checked and unchecked disjoint mutable access from 1.86.0. Vec,LinkedList,BTreeMap, andBTreeSethave stableextract_ifvariants across 1.87.0 and 1.91.0.Filehas portable shared/exclusive locking operations from 1.89.0;RwLockWriteGuard::downgradeis stable from 1.92.0.
Process and allocation primitives
std::io::pipe()integrates anonymous pipes withCommandandStdiofrom 1.87.0; drain output before waiting to avoid a full-pipe deadlock.Box<MaybeUninit<T>>::write, slice-wideMaybeUninitoperations, zeroed smart-pointer allocation, and raw-parts decomposition cover common staged-initialization and ownership-transfer tasks.std::fmt::from_fncreates a display value backed by a formatting callback from 1.93.0.
Const evaluation
- Releases 1.84.0–1.97.0 make many pointer, pinning, numeric, collection-view, string, path, cell, slice, formatting, and character operations const-capable.
- Check standard-library.md for the exact method and minimum release instead of assuming the runtime-stable API is const-stable.
Target and documentation checks
- Query the host triple with
rustc --print host-tuple, or use Cargo's portablehost-tupletarget where supported. - Review target tier changes before assuming rustup artifacts, host tools, or test guarantees.
- Cross-target doctests now run through configured runners; target-specific failures that were previously skipped may surface.
- Rustdoc target ignores, external doctest runners, search improvements, attribute validation, and emitted-path remapping are detailed in docs-tests-and-formatting.md.
Covered batches
Included versioned batches: 1.84.0, edition-2024, 1.85.0, 1.86.0, 1.87.0, 1.88.0, 1.89.0, 1.90.0, 1.91.0, 1.92.0, 1.93.0, 1.94.0, 1.95.0, 1.96.0, and 1.97.0. Cargo and Rust 2024 supplemental additions are integrated by topic.