rust-lang / rust-lang/rust

Re-add the "perhaps you meant to use an outer attribute" hint to target checking

Open
#147,688 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-attributes A-diagnostics D-lack-of-suggestion T-compiler
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

#![rustc_main]
mod test {

}
Current output
error: `#[rustc_main]` attribute cannot be used on crates
  --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:12:1
   |
LL | #![rustc_main]
   | ^^^^^^^^^^^^^^
   |
   = help: `#[rustc_main]` can only be applied to functions
Desired output
error: `#[rustc_main]` attribute cannot be used on crates
  --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:12:1
   |
LL | #![rustc_main]
   | ^^^^^^^^^^^^^^
   |
   = help: `#[rustc_main]` can only be applied to functions. perhaps you meant to use an outer attribute
   |
LL - #![rustc_main]
LL + #[rustc_main]

This hint was there before the target checking refactor but not after, and I think it is a nice hint for people who are a little confused about the attribute syntax of rust and accidentally used !.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the diagnostic with the issue's #![rustc_main] crate-level attribute example and compare it with the desired output. Trace the target-checking path involved in the regression, then verify that the outer-attribute suggestion and replacement span appear while the existing error remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.