Make sure that labels are defined after the primary span in diagnostics · rust-lang/rust@df72e47 (original) (raw)
File tree
1 file changed
lines changed
- compiler/rustc_macros/src/diagnostics
1 file changed
lines changed
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -269,6 +269,7 @@ impl DiagnosticDeriveVariantBuilder { | ||
| 269 | 269 | let field_binding = &binding_info.binding; |
| 270 | 270 | |
| 271 | 271 | let inner_ty = FieldInnerTy::from_type(&field.ty); |
| 272 | +let mut seen_label = false; | |
| 272 | 273 | |
| 273 | 274 | field |
| 274 | 275 | .attrs |
| @@ -280,6 +281,14 @@ impl DiagnosticDeriveVariantBuilder { | ||
| 280 | 281 | } |
| 281 | 282 | |
| 282 | 283 | let name = attr.path().segments.last().unwrap().ident.to_string(); |
| 284 | + | |
| 285 | +if name == "primary_span" && seen_label { | |
| 286 | +span_err(attr.span().unwrap(), format!("`#[primary_span]` must be placed before labels, since it overwrites the span of the diagnostic")).emit(); | |
| 287 | +} | |
| 288 | +if name == "label" { | |
| 289 | + seen_label = true; | |
| 290 | +} | |
| 291 | + | |
| 283 | 292 | let needs_clone = |
| 284 | 293 | name == "primary_span" && matches!(inner_ty, FieldInnerTy::Vec(_)); |
| 285 | 294 | let (binding, needs_destructure) = if needs_clone { |