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

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

Open
fmease opened this issue Mar 21, 2025 · 0 comments
Open

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

fmease opened this issue Mar 21, 2025 · 0 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fmease
Copy link
Member

fmease commented Mar 21, 2025

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.

@fmease fmease added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 21, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 21, 2025
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 21, 2025
@fmease fmease 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 Mar 21, 2025
@fmease fmease 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 Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants