Skip to content

Commit 2e626a4

Browse files
committed
Auto merge of #154722 - JayanAXHF:fix/update-ignore-error-message, r=<try>
fix(lints): Improve `ill_formed_attribute_input` with better help message try-job: i686-msvc-2
2 parents 9602bda + 65b88ea commit 2e626a4

File tree

9 files changed

+67
-5
lines changed

9 files changed

+67
-5
lines changed

compiler/rustc_attr_parsing/src/attributes/doc.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,11 @@ impl DocParser {
665665
let span = cx.attr_span;
666666
cx.emit_lint(
667667
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
668-
AttributeLintKind::IllFormedAttributeInput { suggestions, docs: None },
668+
AttributeLintKind::IllFormedAttributeInput {
669+
suggestions,
670+
docs: None,
671+
help: None,
672+
},
669673
span,
670674
);
671675
}

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@ impl<S: Stage> SingleAttributeParser<S> for IgnoreParser {
2727
};
2828
Some(str_value)
2929
}
30-
ArgParser::List(_) => {
31-
cx.adcx().warn_ill_formed_attribute_input(ILL_FORMED_ATTRIBUTE_INPUT);
30+
ArgParser::List(list) => {
31+
let help = list.single().and_then(|item| item.meta_item()).and_then(|item| {
32+
item.args().no_args().ok()?;
33+
Some(item.path().to_string())
34+
});
35+
cx.adcx().warn_ill_formed_attribute_input_with_help(
36+
ILL_FORMED_ATTRIBUTE_INPUT,
37+
help,
38+
);
3239
return None;
3340
}
3441
},

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,11 +830,18 @@ where
830830
}
831831

832832
pub(crate) fn warn_ill_formed_attribute_input(&mut self, lint: &'static Lint) {
833+
self.warn_ill_formed_attribute_input_with_help(lint, None)
834+
}
835+
pub(crate) fn warn_ill_formed_attribute_input_with_help(
836+
&mut self,
837+
lint: &'static Lint,
838+
help: Option<String>,
839+
) {
833840
let suggestions = self.suggestions();
834841
let span = self.attr_span;
835842
self.emit_lint(
836843
lint,
837-
AttributeLintKind::IllFormedAttributeInput { suggestions, docs: None },
844+
AttributeLintKind::IllFormedAttributeInput { suggestions, docs: None, help },
838845
span,
839846
);
840847
}

compiler/rustc_attr_parsing/src/validate_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ fn emit_malformed_attribute(
211211
BuiltinLintDiag::AttributeLint(AttributeLintKind::IllFormedAttributeInput {
212212
suggestions: suggestions.clone(),
213213
docs: template.docs,
214+
help: None,
214215
}),
215216
);
216217
} else {

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,15 @@ impl<'a> Diagnostic<'a, ()> for DecorateAttrLint<'_, '_, '_> {
137137
&AttributeLintKind::UnusedDuplicate { this, other, warning } => {
138138
lints::UnusedDuplicate { this, other, warning }.into_diag(dcx, level)
139139
}
140-
AttributeLintKind::IllFormedAttributeInput { suggestions, docs } => {
140+
AttributeLintKind::IllFormedAttributeInput { suggestions, docs, help } => {
141141
lints::IllFormedAttributeInput {
142142
num_suggestions: suggestions.len(),
143143
suggestions: DiagArgValue::StrListSepByAnd(
144144
suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(),
145145
),
146146
has_docs: docs.is_some(),
147147
docs: docs.unwrap_or(""),
148+
help: help.clone().map(|h| lints::IllFormedAttributeInputHelp { lint: h }),
148149
}
149150
.into_diag(dcx, level)
150151
}

compiler/rustc_lint/src/lints.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,6 +3009,16 @@ pub(crate) struct IllFormedAttributeInput {
30093009
#[note("for more information, visit <{$docs}>")]
30103010
pub has_docs: bool,
30113011
pub docs: &'static str,
3012+
#[subdiagnostic]
3013+
pub help: Option<IllFormedAttributeInputHelp>,
3014+
}
3015+
3016+
#[derive(Subdiagnostic)]
3017+
#[help(
3018+
"if you meant to silence a warning, consider using #![allow({$lint})] or #![expect({$lint})]"
3019+
)]
3020+
pub(crate) struct IllFormedAttributeInputHelp {
3021+
pub lint: String,
30123022
}
30133023

30143024
#[derive(Diagnostic)]

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ pub enum AttributeLintKind {
690690
IllFormedAttributeInput {
691691
suggestions: Vec<String>,
692692
docs: Option<&'static str>,
693+
help: Option<String>,
693694
},
694695
EmptyAttribute {
695696
first_span: Span,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[ignore(clippy::single_match)]
2+
//~^ ERROR valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]`
3+
//~| HELP if you meant to silence a warning, consider using #![allow(clippy::single_match)] or #![expect(clippy::single_match)]
4+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
5+
6+
fn main() {}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]`
2+
--> $DIR/ignore-with-lint-name.rs:1:1
3+
|
4+
LL | #[ignore(clippy::single_match)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: if you meant to silence a warning, consider using #![allow(clippy::single_match)] or #![expect(clippy::single_match)]
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
10+
= note: `#[deny(ill_formed_attribute_input)]` (part of `#[deny(future_incompatible)]`) on by default
11+
12+
error: aborting due to 1 previous error
13+
14+
Future incompatibility report: Future breakage diagnostic:
15+
error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]`
16+
--> $DIR/ignore-with-lint-name.rs:1:1
17+
|
18+
LL | #[ignore(clippy::single_match)]
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
|
21+
= help: if you meant to silence a warning, consider using #![allow(clippy::single_match)] or #![expect(clippy::single_match)]
22+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
23+
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
24+
= note: `#[deny(ill_formed_attribute_input)]` (part of `#[deny(future_incompatible)]`) on by default
25+

0 commit comments

Comments
 (0)