Ensure code= in #[suggestion(...)] is only set once

This commit is contained in:
Xiretza 2022-09-10 14:28:12 +02:00
parent adcc55d622
commit 2e72387fd0
3 changed files with 23 additions and 3 deletions

View File

@ -476,7 +476,7 @@ impl DiagnosticDeriveBuilder {
match nested_name {
"code" => {
let formatted_str = self.build_format(&s.value(), s.span());
code = Some(formatted_str);
code.set_once((formatted_str, span));
}
"applicability" => {
applicability = match applicability {
@ -524,7 +524,7 @@ impl DiagnosticDeriveBuilder {
let msg = msg.unwrap_or_else(|| parse_quote! { _subdiag::suggestion });
let msg = quote! { rustc_errors::fluent::#msg };
let code = code.unwrap_or_else(|| quote! { String::new() });
let code = code.value().unwrap_or_else(|| quote! { String::new() });
Ok(quote! { #diag.#method(#span_field, #msg, #code, #applicability); })
}

View File

@ -581,3 +581,11 @@ struct LintAttributeOnSessionDiag {}
//~| ERROR diagnostic slug not specified
//~| ERROR cannot find attribute `lint` in this scope
struct LintAttributeOnLintDiag {}
#[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct DuplicatedSuggestionCode {
#[suggestion(typeck::suggestion, code = "...", code = ",,,")]
//~^ ERROR specified multiple times
suggestion: Span,
}

View File

@ -403,6 +403,18 @@ LL | | struct LintAttributeOnLintDiag {}
|
= help: specify the slug as the first argument to the attribute, such as `#[diag(typeck::example_error)]`
error: specified multiple times
--> $DIR/diagnostic-derive.rs:588:52
|
LL | #[suggestion(typeck::suggestion, code = "...", code = ",,,")]
| ^^^^^^^^^^^^
|
note: previously specified here
--> $DIR/diagnostic-derive.rs:588:38
|
LL | #[suggestion(typeck::suggestion, code = "...", code = ",,,")]
| ^^^^^^^^^^^^
error: cannot find attribute `nonsense` in this scope
--> $DIR/diagnostic-derive.rs:53:3
|
@ -459,7 +471,7 @@ LL | arg: impl IntoDiagnosticArg,
| ^^^^^^^^^^^^^^^^^ required by this bound in `DiagnosticBuilder::<'a, G>::set_arg`
= note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 55 previous errors
error: aborting due to 56 previous errors
Some errors have detailed explanations: E0277, E0425.
For more information about an error, try `rustc --explain E0277`.