Skip to content

Built-in attributes are treated differently vs prelude attributes, unstable built-in attributes can name-collide with stable macro, and built-in attributes can break back-compat #134963

Description

@jieyouxu

Example breakage: Broken build after updating: coverage is ambiguous; ambiguous because of a name conflict with a builtin attribute

Example code:

macro_rules! coverage {
    () => {
        /* .. */
    };
}

pub(crate) use coverage; // `use` here becomes ambiguous

test is similar to a proc-macro, which is exposed via the prelude. It is not a "built-in" attribute.

The reference hasn't really been updated from when that changed. The sub-namespace section also probably should be clearer on what it means to shadow. I also don't have a good explanation why a prelude attribute is treated differently from a built-in one.

Originally posted by @ehuss in #121157

This is an interesting problem that has three aspects:

  1. (T-compiler) Built-in attributes like #[coverage(..)] are handled differently versus prelude attributes like #[test], including name resolution.
  2. (T-compiler) Current feature-gating of unstable built-in attributes is insufficient: adding a new unstable built-in attribute gated behind a feature gate (e.g. #[coverage]) can still break stable code without any feature gates (e.g. use of a user-defined macro of the same name as the newly added built-in attribute).
  3. (T-compiler, T-lang) Stabilization of a built-in attribute can break backwards compatibility: old code can be broken by addition of a new built-in attribute.

It might be tricky to change (or not possible), mostly opened this issue for awareness.

Activity

  1. added
    A-attributesArea: Attributes (`#[…]`, `#![…]`)
    A-stabilityArea: `#[stable]`, `#[unstable]` etc.
    C-discussionCategory: Discussion or questions that doesn't represent real issues.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    T-langRelevant to the language team
    on Dec 31, 2024
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Dec 31, 2024
  3. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Dec 31, 2024
  4. jieyouxu commented on Dec 31, 2024

    @jieyouxu
    MemberAuthor

    Nominating for T-compiler discussion, mostly for awareness and if there's anything actionable (feel free to postpone this until holiday is over, just putting it in the nomination queue).

    @rustbot label +I-compiler-nominated

  5. added
    A-resolveArea: Name/path resolution done by `rustc_resolve` specifically
    on Jan 2, 2025
  6. apiraino commented on Jan 15, 2025

    @apiraino
    Contributor

    We briefly looked at this during T-compiler triage on Zulip.

    One question was what is precisely meant by stability of the built-ins to rustc, seems we don't have a good summary for it, we should probably have this behaviour documented somewhere.

    Removing the nomination for now. In case feel free to nominate for T-compiler discussion again.
    @rustbot label -I-compiler-nominated

  7. petrochenkov commented on Jan 15, 2025

    @petrochenkov
    Contributor

    #53913 has relevant information about the current behavior.

  8. added
    I-lang-radarItems that are on lang's radar and will need eventual work or consideration.
    and removed
    I-lang-nominatedNominated for discussion during a lang team meeting.
    on Jan 27, 2025
  9. added
    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
    on Jul 15, 2025
  10. jieyouxu commented on Jul 15, 2025

    @jieyouxu
    MemberAuthor
  11. yaahc commented on Dec 5, 2025

    @yaahc
    Member
  12. jieyouxu commented on Jul 18, 2026

    @jieyouxu
    MemberAuthor
  13. teor2345 commented on Jul 19, 2026

    @teor2345
    Member

    Here's an explanation of the original change that did this (the ticket is linked above, but this is the specific comment):
    #53913 (comment)

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-attributesArea: Attributes (`#[…]`, `#![…]`)A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyA-stabilityArea: `#[stable]`, `#[unstable]` etc.C-discussionCategory: Discussion or questions that doesn't represent real issues.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions