Skip to content

actual "crate root" file not identified in diagnostics #157001

Description

@workingjubilee

Code

// inside some file that is inside a crate's tests
#![feature(something)]

Current output

warning: the `#![feature]` attribute can only be used at the crate root

Desired output

warning: the `#![feature]` attribute can only be used at the crate root

...

help: add `#![feature(something)]` to path/to/crate/root/lib.rs

Rationale and extra context

Normally the crate root file is fairly obvious but there are cases, like with integration tests, where it is not. Even for more experienced programmers, "crate root" can be a slightly puzzling turn of phrase.

Other cases

Rust Version

rustc 1.96.0-nightly (55e86c996 2026-04-02)
binary: rustc
commit-hash: 55e86c996809902e8bbad512cfb4d2c18be446d9
commit-date: 2026-04-02
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.2

Anything else?

Issue is an extraction from #144935 (comment)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions