mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Auto merge of #152452 - ShE3py:overruled-lint, r=BoxyUwU
feat: show what lint was overruled We can't `#[allow]` a whole lint group if any of its members is forbidden, but the offending member is not currently shown if it was forbidden from the command line. Before/after: ```diff $ rustc -F dead_code - <<< '#![allow(unused)]' error[E0453]: allow(unused) incompatible with previous forbid --> <anon>:1:10 | 1 | #![allow(unused)] | ^^^^^^ overruled by previous forbid | - = note: `forbid` lint level was set on command line + = note: `forbid` lint level was set on command line (`-F dead_code`) error: aborting due to 1 previous error ``` @rustbot label +A-diagnostics +A-lints +D-terse
This commit is contained in:
@@ -20,7 +20,7 @@ pub(crate) struct OverruledAttribute<'a> {
|
||||
pub(crate) enum OverruledAttributeSub {
|
||||
DefaultSource { id: String },
|
||||
NodeSource { span: Span, reason: Option<Symbol> },
|
||||
CommandLineSource,
|
||||
CommandLineSource { id: Symbol },
|
||||
}
|
||||
|
||||
impl Subdiagnostic for OverruledAttributeSub {
|
||||
@@ -36,8 +36,9 @@ fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
|
||||
diag.note(rationale.to_string());
|
||||
}
|
||||
}
|
||||
OverruledAttributeSub::CommandLineSource => {
|
||||
diag.note(msg!("`forbid` lint level was set on command line"));
|
||||
OverruledAttributeSub::CommandLineSource { id } => {
|
||||
diag.note(msg!("`forbid` lint level was set on command line (`-F {$id}`)"));
|
||||
diag.arg("id", id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -580,7 +580,9 @@ fn insert_spec(&mut self, id: LintId, LevelAndSource { level, lint_id, src }: Le
|
||||
LintLevelSource::Node { span, reason, .. } => {
|
||||
OverruledAttributeSub::NodeSource { span, reason }
|
||||
}
|
||||
LintLevelSource::CommandLine(_, _) => OverruledAttributeSub::CommandLineSource,
|
||||
LintLevelSource::CommandLine(name, _) => {
|
||||
OverruledAttributeSub::CommandLineSource { id: name }
|
||||
}
|
||||
};
|
||||
if !fcw_warning {
|
||||
self.sess.dcx().emit_err(OverruledAttribute {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#![forbid(deprecated)]
|
||||
#![forbid(deprecated)] //~ NOTE `forbid` level set here
|
||||
|
||||
#[allow(deprecated)]
|
||||
//~^ ERROR allow(deprecated) incompatible
|
||||
//~^ ERROR allow(deprecated) incompatible with previous forbid [E0453]
|
||||
//~^^ NOTE overruled by previous forbid
|
||||
fn main() {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
//@ compile-flags: -F deprecated
|
||||
|
||||
#[allow(deprecated)] //~ ERROR allow(deprecated) incompatible with previous forbid [E0453]
|
||||
fn main() {
|
||||
}
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
error[E0453]: allow(deprecated) incompatible with previous forbid
|
||||
--> $DIR/lint-forbid-cmdline.rs:3:9
|
||||
--> $DIR/lint-forbid-cmdline-1.rs:3:9
|
||||
|
|
||||
LL | #[allow(deprecated)]
|
||||
| ^^^^^^^^^^ overruled by previous forbid
|
||||
|
|
||||
= note: `forbid` lint level was set on command line
|
||||
= note: `forbid` lint level was set on command line (`-F deprecated`)
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
//@ compile-flags: -F dead_code
|
||||
|
||||
#[allow(unused)]
|
||||
//~^ ERROR allow(unused) incompatible with previous forbid [E0453]
|
||||
//~| NOTE overruled by previous forbid
|
||||
//~| NOTE `forbid` lint level was set on command line (`-F dead_code`)
|
||||
fn main() {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
error[E0453]: allow(unused) incompatible with previous forbid
|
||||
--> $DIR/lint-forbid-cmdline-2.rs:3:9
|
||||
|
|
||||
LL | #[allow(unused)]
|
||||
| ^^^^^^ overruled by previous forbid
|
||||
|
|
||||
= note: `forbid` lint level was set on command line (`-F dead_code`)
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0453`.
|
||||
@@ -1,5 +0,0 @@
|
||||
//@ compile-flags: -F deprecated
|
||||
|
||||
#[allow(deprecated)] //~ ERROR allow(deprecated) incompatible
|
||||
fn main() {
|
||||
}
|
||||
Reference in New Issue
Block a user