Rust Flags & Options
Memory-safe systems language and its compiler, rustc.All Rust pages
- rustc --edition: compile with Rust 2015, 2018, 2021 or 2024rustc --edition 2015, 2018, 2021 or 2024 selects the Rust edition. Plain rustc defaults to 2015 unlike Cargo, so keywords like async and gen behave differently.
- rustc --test: build a test runner from a single Rust filerustc --test builds a libtest runner from a single Rust file without Cargo. Running, filtering and listing tests, the test binary options and exit code 101.
- rustc -C opt-level and -O: optimization levels 0-3, s and zrustc -C opt-level=0-3, s, z and -O set Rust optimization levels. Default 0, overflow checks and debug assertions per level, Cargo profiles, pitfalls.
- rustc -D warnings (RUSTFLAGS="-D warnings"): treat warnings as errorsrustc -D warnings and RUSTFLAGS with -D warnings make Rust lint warnings fail the build. Lint levels -A -W -D -F, allowed lints, the [lints] table, CI.