Make unknown/renamed/removed lints passed via command line respect lint levels #667
Closed
1 of 3 tasks
Labels
major-change
A proposal to make a major change to rustc
major-change-accepted
A major change proposal that was accepted
T-compiler
Add this label so rfcbot knows to poll the compiler team
Proposal
Background
When you specify an unknown/renamed/removed lint name in Rust code, for example
#![deny(foo)]
, the compiler respects the lint system and emits a warning by default1.However, if it is from the command line, such as
-D foo
, the compiler simply emits an error and exits2. There is no way to recover from the error, since those errors are emitted directly viaSession
, not under the control ofLintContext
orLintLevelsbuilder
.Possible solution
This MCP proposes that those errors should be considered as normal lints and emitted by the lint system. Specifically,
CheckNameRenamed
error withrenamed-and-removed-lints
.CheckNameRemoved
error withrenamed-and-removed-lints
.CheckNameDeprecated
error withrenamed-and-removed-lints
.CheckNameUnknown
error withunknown-lints
The proposed behavior is more consistent from both source-code level and end-user perspective.
User-facing impact
Compiler invocations that rely on the aforementioned always-error-out behavior will become valid. This is easy to fix by adding
-D unknown-lints
or-D renamed-and-removed-lints
as a command line argument (tbh not as easy as it looks like3).Motivation
With
-Zlints
unstable feature in Cargo, you can specify lint rules and levels inCargo.toml
. Under the hood Cargo aggregates those settings and passes via command line to the compiler.Without this MCP, it is not backward compatible when a user adds a new lint, and then use an old version of the compiler. The compiler will refuse to compile even
unknown-lints
lint iswarn
by default notdeny
.See rust-lang/cargo#12495.
Compiler version
Mentors or Reviewers
Not sure. Perhaps @estebank or @compiler-errors?
Process
The main points of the Major Change Process are as follows:
@rustbot second
.-C flag
, then full team check-off is required.@rfcbot fcp merge
on either the MCP or the PR.You can read more about Major Change Proposals on forge.
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.
Footnotes
https://github.com/rust-lang/rust/blob/738df13e8a73d6d95ddec81b7393b2d2a64b7e93/compiler/rustc_lint/src/levels.rs#L918-L951 ↩
https://github.com/rust-lang/rust/blob/738df13e8a73d6d95ddec81b7393b2d2a64b7e93/compiler/rustc_lint/src/context.rs#L347-L367 ↩
This is another command line argument precedence issue. Think about this. Which should emit an unknown lint error?
-Dunknown-lints -Dfoo
or-Dfoo -Dunknown-lints
? Or should we make these lints a special priority likewarnings
lint group? That may lead to https://github.com/rust-lang/rust/issues/75668 though. Anyway, this belongs to a separate MCP. ↩The text was updated successfully, but these errors were encountered: