Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/rustc_attr_parsing/src/attributes/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,11 @@ impl DocParser {
let span = cx.attr_span;
cx.emit_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
AttributeLintKind::IllFormedAttributeInput { suggestions, docs: None },
AttributeLintKind::IllFormedAttributeInput {
suggestions,
docs: None,
help: None,
},
span,
);
}
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_attr_parsing/src/attributes/test_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ impl<S: Stage> SingleAttributeParser<S> for IgnoreParser {
};
Some(str_value)
}
ArgParser::List(_) => {
cx.adcx().warn_ill_formed_attribute_input(ILL_FORMED_ATTRIBUTE_INPUT);
ArgParser::List(list) => {
let help = list.single().and_then(|item| item.meta_item()).and_then(|item| {
item.args().no_args().ok()?;
Some(item.path().to_string())
});
cx.warn_ill_formed_attribute_input_with_help(ILL_FORMED_ATTRIBUTE_INPUT, help);
return None;
}
},
Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,11 +815,19 @@ where
}

pub(crate) fn warn_ill_formed_attribute_input(&mut self, lint: &'static Lint) {
self.warn_ill_formed_attribute_input_with_help(lint, None);
}

pub(crate) fn warn_ill_formed_attribute_input_with_help(
&mut self,
lint: &'static Lint,
help: Option<String>,
) {
let suggestions = self.suggestions();
let span = self.attr_span;
self.emit_lint(
lint,
AttributeLintKind::IllFormedAttributeInput { suggestions, docs: None },
AttributeLintKind::IllFormedAttributeInput { suggestions, docs: None, help },
span,
);
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_attr_parsing/src/validate_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ fn emit_malformed_attribute(
BuiltinLintDiag::AttributeLint(AttributeLintKind::IllFormedAttributeInput {
suggestions: suggestions.clone(),
docs: template.docs,
help: None,
}),
);
} else {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_lint/src/early/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,15 @@ impl<'a> Diagnostic<'a, ()> for DecorateAttrLint<'_, '_, '_> {
&AttributeLintKind::UnusedDuplicate { this, other, warning } => {
lints::UnusedDuplicate { this, other, warning }.into_diag(dcx, level)
}
AttributeLintKind::IllFormedAttributeInput { suggestions, docs } => {
AttributeLintKind::IllFormedAttributeInput { suggestions, docs, help } => {
lints::IllFormedAttributeInput {
num_suggestions: suggestions.len(),
suggestions: DiagArgValue::StrListSepByAnd(
suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(),
),
has_docs: docs.is_some(),
docs: docs.unwrap_or(""),
help: help.clone().map(|h| lints::IllFormedAttributeInputHelp { lint: h }),
}
.into_diag(dcx, level)
}
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3009,6 +3009,16 @@ pub(crate) struct IllFormedAttributeInput {
#[note("for more information, visit <{$docs}>")]
pub has_docs: bool,
pub docs: &'static str,
#[subdiagnostic]
pub help: Option<IllFormedAttributeInputHelp>,
}

#[derive(Subdiagnostic)]
#[help(
"if you meant to silence a warning, consider using #![allow({$lint})] or #![expect({$lint})]"
)]
pub(crate) struct IllFormedAttributeInputHelp {
pub lint: String,
}

#[derive(Diagnostic)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ pub enum AttributeLintKind {
IllFormedAttributeInput {
suggestions: Vec<String>,
docs: Option<&'static str>,
help: Option<String>,
},
EmptyAttribute {
first_span: Span,
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/malformed/ignore-with-lint-name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[ignore(clippy::single_match)]
//~^ ERROR valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]`
//~| HELP if you meant to silence a warning, consider using #![allow(clippy::single_match)] or #![expect(clippy::single_match)]
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

fn main() {}
25 changes: 25 additions & 0 deletions tests/ui/malformed/ignore-with-lint-name.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]`
--> $DIR/ignore-with-lint-name.rs:1:1
|
LL | #[ignore(clippy::single_match)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: if you meant to silence a warning, consider using #![allow(clippy::single_match)] or #![expect(clippy::single_match)]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
= note: `#[deny(ill_formed_attribute_input)]` (part of `#[deny(future_incompatible)]`) on by default

error: aborting due to 1 previous error

Future incompatibility report: Future breakage diagnostic:
error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]`
--> $DIR/ignore-with-lint-name.rs:1:1
|
LL | #[ignore(clippy::single_match)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: if you meant to silence a warning, consider using #![allow(clippy::single_match)] or #![expect(clippy::single_match)]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
= note: `#[deny(ill_formed_attribute_input)]` (part of `#[deny(future_incompatible)]`) on by default

Loading