Rust Stable Language Semantics
Use this skill for language semantics: ownership, borrowing, lifetimes, traits, generics, pattern matching, error propagation, and Edition differences. First verify the project's actual toolchain and Minimum Supported Rust Version (MSRV).
For standard-library API selection (which collection, which smart pointer, which string type, which I/O trait), use rust-stdlib. For concrete pattern examples ("how do I write X"), use rust-by-example.
Prerequisites Before Starting
- Run
rustc --version --verboseandcargo --version. - Inspect the
rust-versionfield inrust-toolchain.toml,rust-toolchain, andCargo.toml. - Distinguish between three versions: local toolchain, project MSRV, and current official stable release.
- When encountering version-sensitive APIs, consult Current Stable Baseline and rely on official release notes and API documentation as the final authority.
- If a project is locked to an old version, strictly adhere only to syntaxes and APIs that are already stabilized for that specific version.
Current Offline Baseline: Rust 1.97.1 (released July 16, 2026). This is a dated repository baseline and does not update automatically.
Capability Boundaries
Suitable For Handling
- Ownership, borrowing, lifetimes, and move semantics.
struct,enum, pattern matching, traits, generics, and associated types.Option,Resulterror propagation, and custom errors (the language mechanism).- Closures (
Fn/FnMut/FnOnce), attribute syntax, format strings (the language mechanism). - Modules, visibility modifiers,
pub/pub(crate)/pub(super). - Edition differences (language-level —
unsafe extern, RPIT capture, match ergonomics). - Common compilation errors, borrowing check failures, and stable migration judgments.
Hand Off to Specialized Skills
| User Intent | Preferred Skill |
|---|---|
| "Which std collection / smart pointer / string type should I use?" | rust-stdlib |
| "How do I write X in Rust?" (concrete pattern) | rust-by-example |
| API design (naming, traits, future-proofing, ~100 C-* rules) | rust-api-design |
| Project layout, module trees, workspace structure | rust-workspace, rust-module-layout |
| Cargo.toml dependencies, features, profiles, publishing | rust-cargo-build |
| Dependency governance, supply chain, cargo-deny | rust-dependencies |
| Semver, breaking-change classification, publish workflow | rust-semver |
| Java Maven/Gradle project migration and component replacement | rust-java-migration |
| Java-to-Rust source-test parity, Rust obligations, and migration test audit | rust-java-migration-testing |
| Threads, locks, atomics, channels, Tokio | rust-concurrency |
| Unit tests, integration tests, doctests, coverage | rust-testing |
| Raw pointers, memory layout, FFI, Miri | rust-unsafe-ffi |
| UniFFI-generated Kotlin, Swift, Python, Ruby, or WASM bindings | rust-uniffi-building |
| macro_rules, derive, procedural macros | rust-macros |
| Command contracts, standard streams, exit codes, CLI | rust-cli |
| Server-side HTTP APIs, handlers, middleware | rust-web |
| SQL/ORMs, schemas, migrations, transactions, pools | rust-database |
| Web authentication, authorization, sessions, tokens | rust-web-security |
| Bare-metal firmware, no_std drivers, hardware validation | rust-embedded |
| Risk, correctness, API and safety review | rust-code-review |
| rustfmt, Clippy, Edition migration, lint policy | rust-style-clippy |
Do not replace the complete workflow of domain-specific skills with this skill.
Workflow
- Determine Version Boundaries — Record toolchain version, edition, MSRV, and target platform(s).
- Narrow Problem Scope — Determine whether the issue belongs to ownership/type system/standard library/compiler errors or a specialized domain.
- Read Minimal Resources — Open only references directly relevant to the problem; do not load entire documentation sets at once.
- Implement Minimum Correct Solution — Prioritize stable standard library usage, clear ownership semantics, and explicit error propagation.
- Run Quality Gate Checks — Execute
cargo fmt --check,cargo check(with all targets/features), and relevant tests. - Handle Version Differences — If an API is not supported by MSRV, choose the old compatible API or implement a compatibility shim; otherwise explicitly raise the MSRV.
- Transfer to Specialized Skills — Load corresponding skills for async, unsafe macros, Web, embedded domains after entering those areas.
Design Rules
- Prefer
&T/&mut T; clone only when ownership transfer is required or independent lifetimes are needed. - Use types to express invariants; prefer enums/newtypes over boolean parameters and unconstrained strings.
- Library code should return structured errors; application boundaries may add context before deciding how to display them.
- Prefer iterators and standard collections, but do not sacrifice readability for chain-of-call syntax.
- Do not use
unsafeas a bypass for borrowing checks first prove that safe abstractions cannot express the requirement. - Do not default third-party crate imports; compare against stable std, MSRV, maintenance cost, and supply chain risk.
- Never claim an API is stabilized in a specific version unless official release notes or an API page marked with
sinceconfirm it.
Validation Gateways
Run validation gates from lowest to highest risk:
cargo fmt --all --check
cargo check --all-targets --all-features
cargo test --all-targets --all-features
cargo clippy --all-targets --all-features -- -D warnings
If the project does not support --all-features or contains platform-specific targets, record reasons and use a defined feature/target matrix. For unsafe code, add cargo miri test; for MSRV issues, repeat cargo check and tests on the declared minimum toolchain.
Required Documentation to Read On-Demand
Version & Language Semantics
- Current Stable Baseline: Latest version, compatibility notes, update steps.
- Ownership & Lifetimes: Borrowing design, return values and lifetime judgment rules.
- Traits & Generics: Bounds, associated types, trait objects, API trade-offs.
- Patterns & Idiomatic Style: Builder patterns, newtypes, RAII, typestate management.
- Style Guide: Naming conventions, module organization, documentation style, and API design principles.
Cross-references (load the right skill instead)
- "Which std collection / smart pointer / string type?" →
rust-stdlib(itsreferences/covers collections, smart-pointers, string-types, iterators, I/O, interior-mutability, combinators, std-concurrency, process-and-fs, std-module-index) - "How do I write X?" →
rust-by-example(itsreferences/covers conversions, flow-control, closures, modules, generics-traits, error-handling, attributes, unsafe, procedural-macros-overview, inline-asm, migrating-from-other-languages) - API design →
rust-api-design; Cargo manifest →rust-cargo-build; dependency governance →rust-dependencies
Reproducible Examples
- Quick Start Workflows
- Ownership Patterns (
examples/ownership-patterns.md) - Collection Patterns (
examples/collections-patterns.md) - Trait Design Patterns (
examples/trait-design-patterns.md) - Error Handling Patterns (
examples/error-handling-patterns.md) examples/golden-basic/: Minimal golden examples compiled by repository CI.
Common Pitfalls to Avoid
- Confusing "current stable" with project MSRV.
- Running only
cargo check, omitting tests, examples, benchmarks, or feature combinations. - Blindly using
clone, wrapping inArc<Mutex<_>>, or invokingunsafesolely to avoid borrowing errors. - Holding synchronous locks across
.awaitcalls in async code. - Describing versioned historical documentation as continuously updated resources.
- Copying code snippets without including dependencies, features, error types, and platform constraints.
Official Sources
- Rust Release Notes
- The Rust Programming Language (Book)
- Standard Library Reference
- Reference Manual
- Rust by Example
- Edition Guide
Data Privacy Policy
This skill provides local knowledge, examples, and validation workflows only. It does not collect, store, or transmit user data. Access to official documentation must comply with the user's network access requirements prior to accessing public resources.