Files
rust/tests
Matthias Krüger 89777addb4 Rollup merge of #157025 - Dnreikronos:fix/crate-root-path-help-in-attr-style-diagnostic, r=JonathanBrouwer
Show crate root path in misplaced crate-level attribute diagnostic

Fixes rust-lang/rust#157001

If you put `#![feature(...)]` inside a non-root module, the diagnostic tells you it can only be used at the crate root, but never says where the crate root actually is. Not great if you're new to Rust or working in a big workspace with nested modules.

Now the diagnostic includes a help line with the crate root file path when the misplaced attribute is an inner attribute. Outer attributes already get a span note pointing at what they're applied to, so they don't need this. Path goes through `RemapPathScopeComponents::DIAGNOSTICS` so `--remap-path-prefix` is respected.

```
warning: the `#![feature]` attribute can only be used at the crate root
  --> src/foo.rs:1:1
   |
LL | #![feature(test)]
   | ^^^^^^^^^^^^^^^^^
   |
   = help: the crate root is at `src/main.rs`
```
2026-05-28 07:53:38 +02:00
..