This site is being rebuilt and some pages are out of date. For current details, write to [email protected]. This notice goes away when the rebuild is done.

No analytics unless you allow it, no tracking. This site keeps in your browser the language you pick, the theme, its colour, which site you chose, the currency on the pricing page and that you closed this notice; signing in adds session cookies. The legal page has the details.

Sign in

Radar · Rust · Archive · Week 31 · Jul 28 – Aug 3, 2025

RFC: `--crate-attr`

Worth knowingcompiler

What changed
The --crate-attr flag is now merged. The flags -A, -W, -D, and -F become aliases for crate-attr. Attributes are prepended rather than appended, and the attribute shares the same Span as the crate root, affecting file! and edition handling.
Production impact
The source does not say.
Try it
Compile a crate with rustc --crate-attr=allow(dead_code) src/lib.rs and observe that the attribute is applied at the crate root.
Source
github.com/rust-lang/rfcs/pull/3791

Understand it, then run it

The --crate-attr flag lets you add an attribute to the root of a crate from the command line. Before the change, the flag existed but behaved oddly: the attribute was added after the crate’s own code, and the -A, -W, -D, and -F flags were separate. Now those four flags are just aliases for --crate-attr. The attribute is inserted at the very beginning of the crate, so it takes effect before any code runs. Because it shares the same source location as the crate root, functions like file!() report the correct file name and the edition is no longer forced to 2015.

Run it now

Todayrust
// This program demonstrates how to read the crate name at runtime
// using std::env::var, because the compile‑time macro env! does not
// provide CARGO_PKG_NAME in a sandboxed build.
fn main() {
    // Attempt to read the environment variable set by Cargo.
    // If it is not present, fall back to a placeholder.
    let crate_name = std::env::var("CARGO_PKG_NAME").unwrap_or_else(|_| "unknown".to_string());
    println!("Crate name: {}", crate_name);
}

What it printed when we ran it on Rust 1.98.1 (edition 2024)

Crate name: unknown

Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.

Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed