Skip to content

Arguably-internal lint scope rustc isn't protected by a feature gate #138787

Open
@fmease

Description

@fmease

While we manually reject1 attribute paths that contain a path segment that starts with the string rustc2 in order to protect internal attributes

/* assume the user defined `rustc`, `rustc_attr`, `rustcorrosion` or don't */

#[rustc::property] //~ ERROR attributes starting with `rustc` are reserved
#[rustc_attr] //~ ERROR attributes starting with `rustc` are reserved
#[rustcorrosion] //~ ERROR attributes starting with `rustc` are reserved
fn main() {}

we don't have a similar mechanism in place for "lint paths", i.e., paths given as arguments to lint attributes like allow and deny. The following code passes compilation without any warnings which I didn't expect:

#![allow(rustc::internals)]
#![deny(rustc::i_do_not_exist)]

Why could this be considered problematic? Rustc should be allowed to remove or rename the lint scope rustc without impacting stable users. However, if rustc did do so, it would break the code of hypothetical stable users who started to "rely" on these lint paths existing. Why would it break their code? Well, undefined lint scopes currently result in a hard error (unlike unknown lints for which we emit the warn-by-default lint unknown-lints):

#![allow(undefined::lint)] //~ ERROR unknown tool name `undefined` found in scoped lint: `undefined::lint` [E0710]

Of course, that scenario is quite unlikely to happen in practice. This is slightly above P-low territory I'd say.


I think we should reject lint scope rustc unless internal feature rustc_attrs is enabled.

Alternatively, we could think about replacing the hard error E0710 with a deny-by-default lint unknown-lint-scopes (rendering "breakages" caused by renaming/removing the lint scope acceptable as per Rust's stability guarantees) but that might do a disservice to tools using register_tool and wouldn't signal to users that crashes/ICEs caused by running these internal lint passes are not considered bugs.

Footnotes

  1. Unless internal feature rustc_attrs is enabled.

  2. Indeed, this includes "benign" segment idents like rustcorrosion which I find questionable personally speaking (I would at least relax it to IS(rustc) OR STARTSWITH(rustc_)) since users could theoretically encounter this in the wild if they define or use attribute proc macros. I remember there having been heated discussions about replacing that with a proper "tool" module (ToolMod) called rustc with the main(?) counter argument being "rustc is not a tool" which I do understand.

Activity

added
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
C-bugCategory: This is a bug.
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Mar 21, 2025
added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Mar 21, 2025
removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Mar 21, 2025
changed the title [-]Arguably internal lint scope `rustc` isn't protected inside lint paths[/-] [+]Arguably-internal lint scope `rustc` isn't protected inside lint paths[/+] on Mar 21, 2025
changed the title [-]Arguably-internal lint scope `rustc` isn't protected inside lint paths[/-] [+]Arguably-internal lint scope `rustc` isn't protected by a feature gate[/+] on Mar 21, 2025
jyn514

jyn514 commented on Mar 28, 2025

@jyn514
Member

I plan to make an RFC for register_tool soon, I'd appreciate it if you could hold off on making changes for the next couple months.

My initial reaction is that this should behave the same as other lints for unknown tools. but I am considering changing that behavior in the RFC. it would be great to look at the holistic picture here instead of immediately making it a breaking change to match an unstable feature.

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-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.T-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

        Participants

        @fmease@jyn514@rustbot

        Issue actions

          Arguably-internal lint scope `rustc` isn't protected by a feature gate · Issue #138787 · rust-lang/rust