diff options
| author | Xiretza <xiretza@xiretza.xyz> | 2022-08-19 15:04:34 +0200 |
|---|---|---|
| committer | Xiretza <xiretza@xiretza.xyz> | 2022-08-21 09:17:43 +0200 |
| commit | bd0d3f745d40c9de9c5dbc24dc7f8fb64ceb5575 (patch) | |
| tree | 47ee454ab2ae51586f393d399735eb9dd0f44205 /compiler/rustc_macros/src | |
| parent | a960f8304cee9af374aae7bade15554734f37480 (diff) | |
| download | rust-bd0d3f745d40c9de9c5dbc24dc7f8fb64ceb5575.tar.gz rust-bd0d3f745d40c9de9c5dbc24dc7f8fb64ceb5575.zip | |
Disallow #[primary_span] on LintDiagnostics
Diffstat (limited to 'compiler/rustc_macros/src')
| -rw-r--r-- | compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs index 6a5997512bd..31ea6bb779e 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs @@ -340,11 +340,20 @@ impl DiagnosticDeriveBuilder { Ok(quote! {}) } "primary_span" => { - report_error_if_not_applied_to_span(attr, &info)?; + match self.kind { + DiagnosticDeriveKind::SessionDiagnostic => { + report_error_if_not_applied_to_span(attr, &info)?; - Ok(quote! { - #diag.set_span(#binding); - }) + Ok(quote! { + #diag.set_span(#binding); + }) + } + DiagnosticDeriveKind::LintDiagnostic => { + throw_invalid_attr!(attr, &meta, |diag| { + diag.help("the `primary_span` field attribute is not valid for lint diagnostics") + }) + } + } } "label" => { report_error_if_not_applied_to_span(attr, &info)?; |
