Rollup merge of #127591 - compiler-errors:label-after-primary, r=lcnr · rust-lang/rust@73c500b (original) (raw)

File tree

4 files changed

lines changed

4 files 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 {
Original file line number Diff line number Diff line change
@@ -1089,8 +1089,8 @@ pub(crate) struct ToolWasAlreadyRegistered {
1089 1089 #[derive(Diagnostic)]
1090 1090 #[diag(resolve_tool_only_accepts_identifiers)]
1091 1091 pub(crate) struct ToolOnlyAcceptsIdentifiers {
1092 -#[label]
1093 1092 #[primary_span]
1093 +#[label]
1094 1094 pub(crate) span: Span,
1095 1095 pub(crate) tool: Symbol,
1096 1096 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
1 +#![feature(register_tool)]
2 +
3 +#![register_tool(1)]
4 +//~^ ERROR `register_tool` only accepts identifiers
5 +
6 +fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
1 +error: `register_tool` only accepts identifiers
2 + --> $DIR/invalid-tool.rs:3:18
3 + |
4 +LL | #![register_tool(1)]
5 + | ^ not an identifier
6 +
7 +error: aborting due to 1 previous error
8 +