SessionSubdiagnostic: make #[applicability] optional

This commit is contained in:
Xiretza 2022-08-26 11:09:06 +02:00
parent 6e8dad5c07
commit 9dc0643744
3 changed files with 13 additions and 55 deletions

View File

@ -469,14 +469,10 @@ impl<'a> SessionSubdiagnosticDeriveBuilder<'a> {
};
let span_field = self.span_field.as_ref().map(|(span, _)| span);
let applicability = match self.applicability.clone() {
Some((applicability, _)) => Some(applicability),
None if is_suggestion => {
span_err(self.span, "suggestion without `applicability`").emit();
Some(quote! { rustc_errors::Applicability::Unspecified })
}
None => None,
};
let applicability = self.applicability.take().map_or_else(
|| quote! { rustc_errors::Applicability::Unspecified },
|(applicability, _)| applicability,
);
let diag = &self.diag;
let name = format_ident!("{}{}", if span_field.is_some() { "span_" } else { "" }, kind);

View File

@ -401,7 +401,6 @@ struct AK {
#[derive(SessionSubdiagnostic)]
#[suggestion(parser::add_paren, code = "...")]
//~^ ERROR suggestion without `applicability`
struct AL {
#[primary_span]
span: Span,
@ -412,7 +411,6 @@ struct AL {
#[derive(SessionSubdiagnostic)]
#[suggestion(parser::add_paren, code = "...")]
//~^ ERROR suggestion without `applicability`
struct AM {
#[primary_span]
span: Span,
@ -448,8 +446,7 @@ struct AQ;
#[derive(SessionSubdiagnostic)]
#[suggestion(parser::add_paren, code = "...")]
//~^ ERROR suggestion without `applicability`
//~^^ ERROR suggestion without `#[primary_span]` field
//~^ ERROR suggestion without `#[primary_span]` field
struct AR {
var: String,
}

View File

@ -249,36 +249,13 @@ LL | #[applicability]
| ^^^^^^^^^^^^^^^^
error: the `#[applicability]` attribute can only be applied to fields of type `Applicability`
--> $DIR/subdiagnostic-derive.rs:408:5
--> $DIR/subdiagnostic-derive.rs:407:5
|
LL | #[applicability]
| ^^^^^^^^^^^^^^^^
error: suggestion without `applicability`
--> $DIR/subdiagnostic-derive.rs:403:1
|
LL | / #[suggestion(parser::add_paren, code = "...")]
LL | |
LL | | struct AL {
LL | | #[primary_span]
... |
LL | | applicability: Span,
LL | | }
| |_^
error: suggestion without `applicability`
--> $DIR/subdiagnostic-derive.rs:414:1
|
LL | / #[suggestion(parser::add_paren, code = "...")]
LL | |
LL | | struct AM {
LL | | #[primary_span]
LL | | span: Span,
LL | | }
| |_^
error: suggestion without `code = "..."`
--> $DIR/subdiagnostic-derive.rs:422:1
--> $DIR/subdiagnostic-derive.rs:420:1
|
LL | / #[suggestion(parser::add_paren)]
LL | |
@ -290,47 +267,35 @@ LL | | }
| |_^
error: invalid applicability
--> $DIR/subdiagnostic-derive.rs:432:46
--> $DIR/subdiagnostic-derive.rs:430:46
|
LL | #[suggestion(parser::add_paren, code ="...", applicability = "foo")]
| ^^^^^^^^^^^^^^^^^^^^^
error: suggestion without `applicability`
--> $DIR/subdiagnostic-derive.rs:450:1
|
LL | / #[suggestion(parser::add_paren, code = "...")]
LL | |
LL | |
LL | | struct AR {
LL | | var: String,
LL | | }
| |_^
error: suggestion without `#[primary_span]` field
--> $DIR/subdiagnostic-derive.rs:450:1
--> $DIR/subdiagnostic-derive.rs:448:1
|
LL | / #[suggestion(parser::add_paren, code = "...")]
LL | |
LL | |
LL | | struct AR {
LL | | var: String,
LL | | }
| |_^
error: unsupported type attribute for subdiagnostic enum
--> $DIR/subdiagnostic-derive.rs:465:1
--> $DIR/subdiagnostic-derive.rs:462:1
|
LL | #[label]
| ^^^^^^^^
error: `var` doesn't refer to a field on this type
--> $DIR/subdiagnostic-derive.rs:485:39
--> $DIR/subdiagnostic-derive.rs:482:39
|
LL | #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
| ^^^^^^^
error: `var` doesn't refer to a field on this type
--> $DIR/subdiagnostic-derive.rs:504:43
--> $DIR/subdiagnostic-derive.rs:501:43
|
LL | #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
| ^^^^^^^
@ -395,6 +360,6 @@ error[E0425]: cannot find value `slug` in module `rustc_errors::fluent`
LL | #[label(slug)]
| ^^^^ not found in `rustc_errors::fluent`
error: aborting due to 52 previous errors
error: aborting due to 49 previous errors
For more information about this error, try `rustc --explain E0425`.