Skip to content

Commit 57fd974

Browse files
committed
Merge "missing options" lints for diagnostic attributes
1 parent e9d0e32 commit 57fd974

19 files changed

Lines changed: 33 additions & 48 deletions

compiler/rustc_attr_parsing/src/attributes/diagnostic/on_const.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ impl<S: Stage> AttributeParser<S> for OnConstParser {
2929
ArgParser::NoArgs | ArgParser::List(_) => {
3030
cx.emit_lint(
3131
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
32-
AttributeLintKind::MissingOptionsForOnConst,
32+
AttributeLintKind::MissingOptionsForDiagnosticAttribute {
33+
attribute: mode.as_str(),
34+
},
3335
span,
3436
);
3537
return;

compiler/rustc_attr_parsing/src/attributes/diagnostic/on_move.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ impl OnMoveParser {
3232
let Some(list) = args.list() else {
3333
cx.emit_lint(
3434
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
35-
AttributeLintKind::MissingOptionsForOnMove,
35+
AttributeLintKind::MissingOptionsForDiagnosticAttribute {
36+
attribute: mode.as_str(),
37+
},
3638
span,
3739
);
3840
return;

compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unimplemented.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ impl OnUnimplementedParser {
3434
ArgParser::NoArgs | ArgParser::List(_) => {
3535
cx.emit_lint(
3636
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
37-
AttributeLintKind::MissingOptionsForOnUnimplemented,
37+
AttributeLintKind::MissingOptionsForDiagnosticAttribute {
38+
attribute: mode.as_str(),
39+
},
3840
span,
3941
);
4042
return;

compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unknown.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ impl OnUnknownParser {
2828
ArgParser::NoArgs | ArgParser::List(_) => {
2929
cx.emit_lint(
3030
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
31-
AttributeLintKind::MissingOptionsForOnUnknown,
31+
AttributeLintKind::MissingOptionsForDiagnosticAttribute {
32+
attribute: mode.as_str(),
33+
},
3234
span,
3335
);
3436
return;

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,24 +198,15 @@ impl<'a> Diagnostic<'a, ()> for DecorateAttrLint<'_, '_, '_> {
198198
lints::IgnoredDiagnosticOption { option_name, first_span, later_span }
199199
.into_diag(dcx, level)
200200
}
201-
&AttributeLintKind::MissingOptionsForOnUnimplemented => {
202-
lints::MissingOptionsForOnUnimplementedAttr.into_diag(dcx, level)
203-
}
204-
&AttributeLintKind::MissingOptionsForOnConst => {
205-
lints::MissingOptionsForOnConstAttr.into_diag(dcx, level)
201+
&AttributeLintKind::MissingOptionsForDiagnosticAttribute { attribute } => {
202+
lints::MissingOptionsForDiagnosticAttribute { attribute }.into_diag(dcx, level)
206203
}
207204
&AttributeLintKind::OnMoveMalformedFormatLiterals { name } => {
208205
lints::OnMoveMalformedFormatLiterals { name }.into_diag(dcx, level)
209206
}
210207
&AttributeLintKind::OnMoveMalformedAttrExpectedLiteralOrDelimiter => {
211208
lints::OnMoveMalformedAttrExpectedLiteralOrDelimiter.into_diag(dcx, level)
212209
}
213-
&AttributeLintKind::MissingOptionsForOnMove => {
214-
lints::MissingOptionsForOnMoveAttr.into_diag(dcx, level)
215-
}
216-
&AttributeLintKind::MissingOptionsForOnUnknown => {
217-
lints::MissingOptionsForOnUnknownAttr.into_diag(dcx, level)
218-
}
219210
}
220211
}
221212
}

compiler/rustc_lint/src/lints.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3584,24 +3584,11 @@ pub(crate) struct IgnoredDiagnosticOption {
35843584
}
35853585

35863586
#[derive(Diagnostic)]
3587-
#[diag("missing options for `on_unimplemented` attribute")]
3587+
#[diag("missing options for `{$attribute}` attribute")]
35883588
#[help("at least one of the `message`, `note` and `label` options are expected")]
3589-
pub(crate) struct MissingOptionsForOnUnimplementedAttr;
3590-
3591-
#[derive(Diagnostic)]
3592-
#[diag("missing options for `on_unknown` attribute")]
3593-
#[help("at least one of the `message`, `note` and `label` options are expected")]
3594-
pub(crate) struct MissingOptionsForOnUnknownAttr;
3595-
3596-
#[derive(Diagnostic)]
3597-
#[diag("missing options for `on_const` attribute")]
3598-
#[help("at least one of the `message`, `note` and `label` options are expected")]
3599-
pub(crate) struct MissingOptionsForOnConstAttr;
3600-
3601-
#[derive(Diagnostic)]
3602-
#[diag("missing options for `on_move` attribute")]
3603-
#[help("at least one of the `message`, `note` and `label` options are expected")]
3604-
pub(crate) struct MissingOptionsForOnMoveAttr;
3589+
pub(crate) struct MissingOptionsForDiagnosticAttribute {
3590+
pub attribute: &'static str,
3591+
}
36053592

36063593
#[derive(Diagnostic)]
36073594
#[diag("`Eq::assert_receiver_is_total_eq` should never be implemented by hand")]

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,10 +750,9 @@ pub enum AttributeLintKind {
750750
first_span: Span,
751751
later_span: Span,
752752
},
753-
MissingOptionsForOnUnimplemented,
754-
MissingOptionsForOnConst,
755-
MissingOptionsForOnUnknown,
756-
MissingOptionsForOnMove,
753+
MissingOptionsForDiagnosticAttribute {
754+
attribute: &'static str,
755+
},
757756
OnMoveMalformedFormatLiterals {
758757
name: Symbol,
759758
},

tests/ui/attributes/malformed-attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub fn test3() {}
140140
struct Test;
141141

142142
#[diagnostic::on_unimplemented]
143-
//~^ WARN missing options for `on_unimplemented` attribute
143+
//~^ WARN missing options for `diagnostic::on_unimplemented` attribute
144144
#[diagnostic::on_unimplemented = 1]
145145
//~^ WARN malformed
146146
trait Hey {

tests/ui/attributes/malformed-attrs.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ LL | #[no_implicit_prelude = 23]
793793
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
794794
= help: `#[no_implicit_prelude]` can be applied to crates and modules
795795

796-
warning: missing options for `on_unimplemented` attribute
796+
warning: missing options for `diagnostic::on_unimplemented` attribute
797797
--> $DIR/malformed-attrs.rs:142:1
798798
|
799799
LL | #[diagnostic::on_unimplemented]

tests/ui/diagnostic_namespace/on_move/report_warning_on_invalid_meta_item_syntax.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![feature(diagnostic_on_move)]
22

33
#[diagnostic::on_move = "foo"]
4-
//~^WARN missing options for `on_move` attribute [malformed_diagnostic_attributes]
4+
//~^WARN missing options for `diagnostic::on_move` attribute [malformed_diagnostic_attributes]
55
struct Foo;
66

77
fn takes_foo(_: Foo) {}

0 commit comments

Comments
 (0)