diff options
| author | Deadbeef <ent3rm4n@gmail.com> | 2023-04-03 14:36:50 +0000 |
|---|---|---|
| committer | Deadbeef <ent3rm4n@gmail.com> | 2023-04-06 04:55:58 +0000 |
| commit | fc01b4b63c5336a0f296b049525e18798b95b374 (patch) | |
| tree | 5e8da28fb50e4a975731103c92ca99f5c2fbbeb6 /compiler/rustc_macros/src/diagnostics | |
| parent | af74ef89934ad30b24132b464b6b4cf7cb0e1381 (diff) | |
| download | rust-fc01b4b63c5336a0f296b049525e18798b95b374.tar.gz rust-fc01b4b63c5336a0f296b049525e18798b95b374.zip | |
fix and bless ui tests 1/2
Diffstat (limited to 'compiler/rustc_macros/src/diagnostics')
| -rw-r--r-- | compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_macros/src/diagnostics/utils.rs | 13 |
2 files changed, 19 insertions, 1 deletions
diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs index fb75d87f8d2..9b91627883a 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs @@ -214,10 +214,15 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> { if path.is_ident("code") { self.code.set_once((), path.span().unwrap()); - let code = nested.parse::<TokenStream>()?; + let code = nested.parse::<syn::LitStr>()?; tokens.extend(quote! { #diag.code(rustc_errors::DiagnosticId::Error(#code.to_string())); }); + } else { + span_err(path.span().unwrap(), "unknown argument").note("only the `code` parameter is valid after the slug").emit(); + + // consume the buffer so we don't have syntax errors from syn + let _ = nested.parse::<TokenStream>(); } Ok(()) })?; diff --git a/compiler/rustc_macros/src/diagnostics/utils.rs b/compiler/rustc_macros/src/diagnostics/utils.rs index 38292df6d85..bc104941c38 100644 --- a/compiler/rustc_macros/src/diagnostics/utils.rs +++ b/compiler/rustc_macros/src/diagnostics/utils.rs @@ -716,6 +716,9 @@ impl SubdiagnosticKind { } } + let mut has_errors = false; + let input = nested.input; + match (nested_name, &mut kind) { ("code", SubdiagnosticKind::Suggestion { code_field, .. }) => { let code_init = build_suggestion_code( @@ -734,6 +737,7 @@ impl SubdiagnosticKind { let value = get_string!(); let value = Applicability::from_str(&value.value()).unwrap_or_else(|()| { span_err(value.span().unwrap(), "invalid applicability").emit(); + has_errors = true; Applicability::Unspecified }); applicability.set_once(value, span); @@ -749,6 +753,7 @@ impl SubdiagnosticKind { span_err(value.span().unwrap(), "invalid suggestion style") .help("valid styles are `normal`, `short`, `hidden`, `verbose` and `tool-only`") .emit(); + has_errors = true; SuggestionKind::Normal }); @@ -762,17 +767,25 @@ impl SubdiagnosticKind { "only `style`, `code` and `applicability` are valid nested attributes", ) .emit(); + has_errors = true; } (_, SubdiagnosticKind::MultipartSuggestion { .. }) => { span_err(path_span, "invalid nested attribute") .help("only `style` and `applicability` are valid nested attributes") .emit(); + has_errors = true; } _ => { span_err(path_span, "invalid nested attribute").emit(); + has_errors = true; } } + if has_errors { + // Consume the rest of the input to avoid spamming errors + let _ = input.parse::<TokenStream>(); + } + Ok(()) })?; |
