Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jieyouxu opened this issue Dec 31, 2024 · 1 comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically A-stability Area: `#[stable]`, `#[unstable]` etc. C-discussion Category: Discussion or questions that doesn't represent real issues. I-compiler-nominated Nominated for discussion during a compiler team meeting. I-lang-nominated Nominated for discussion during a lang team meeting. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@jieyouxu
Copy link
Member

jieyouxu commented Dec 31, 2024

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.

@jieyouxu jieyouxu added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-stability Area: `#[stable]`, `#[unstable]` etc. C-discussion Category: Discussion or questions that doesn't represent real issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Dec 31, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 31, 2024
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 31, 2024
@jieyouxu
Copy link
Member Author

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

@rustbot rustbot added the I-compiler-nominated Nominated for discussion during a compiler team meeting. label Dec 31, 2024
@traviscross traviscross added the I-lang-nominated Nominated for discussion during a lang team meeting. label Dec 31, 2024
@jieyouxu jieyouxu added the A-resolve Area: Name/path resolution done by `rustc_resolve` specifically label Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically A-stability Area: `#[stable]`, `#[unstable]` etc. C-discussion Category: Discussion or questions that doesn't represent real issues. I-compiler-nominated Nominated for discussion during a compiler team meeting. I-lang-nominated Nominated for discussion during a lang team meeting. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants