From 0bf3f5d51cb853884240792818d81e70daec6ab7 Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Sun, 25 Jan 2026 22:41:56 +0100 Subject: [PATCH] Remove unused `no_span` option --- .../src/diagnostics/diagnostic_builder.rs | 2 +- .../src/diagnostics/subdiagnostic.rs | 23 ++++++------------- .../rustc_macros/src/diagnostics/utils.rs | 15 +++++------- .../session-diagnostic/diagnostic-derive.rs | 4 ++-- .../diagnostic-derive.stderr | 8 +++---- .../subdiagnostic-derive.rs | 12 +++++----- .../subdiagnostic-derive.stderr | 14 +++++------ 7 files changed, 33 insertions(+), 45 deletions(-) diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs index e71c84c805a7..748d1d3a60f3 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs @@ -192,7 +192,7 @@ fn parse_subdiag_attribute( SubdiagnosticKind::MultipartSuggestion { .. } => unreachable!(), }); - Ok(Some((subdiag.kind, slug, subdiag.no_span))) + Ok(Some((subdiag.kind, slug, false))) } /// Establishes state in the `DiagnosticDeriveBuilder` resulting from the struct diff --git a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs index 189d83c42160..e00d175fc295 100644 --- a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs @@ -188,13 +188,11 @@ fn from_iter>(kinds: T) -> Self { } impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { - fn identify_kind( - &mut self, - ) -> Result, DiagnosticDeriveError> { + fn identify_kind(&mut self) -> Result, DiagnosticDeriveError> { let mut kind_slugs = vec![]; for attr in self.variant.ast().attrs { - let Some(SubdiagnosticVariant { kind, slug, no_span }) = + let Some(SubdiagnosticVariant { kind, slug }) = SubdiagnosticVariant::from_attr(attr, self)? else { // Some attributes aren't errors - like documentation comments - but also aren't @@ -214,7 +212,7 @@ fn identify_kind( ); }; - kind_slugs.push((kind, slug, no_span)); + kind_slugs.push((kind, slug)); } Ok(kind_slugs) @@ -505,8 +503,7 @@ fn generate_field_code_inner_list( pub(crate) fn into_tokens(&mut self) -> Result { let kind_slugs = self.identify_kind()?; - let kind_stats: KindsStatistics = - kind_slugs.iter().map(|(kind, _slug, _no_span)| kind).collect(); + let kind_stats: KindsStatistics = kind_slugs.iter().map(|(kind, _slug)| kind).collect(); let init = if kind_stats.has_multipart_suggestion { quote! { let mut suggestions = Vec::new(); } @@ -539,17 +536,13 @@ pub(crate) fn into_tokens(&mut self) -> Result Result { - if let Some(span) = span_field - && !no_span - { + if let Some(span) = span_field { quote! { #diag.#name(#span, #message); } } else { quote! { #diag.#name(#message); } diff --git a/compiler/rustc_macros/src/diagnostics/utils.rs b/compiler/rustc_macros/src/diagnostics/utils.rs index 6ca2c90abb90..4c73e6d453e9 100644 --- a/compiler/rustc_macros/src/diagnostics/utils.rs +++ b/compiler/rustc_macros/src/diagnostics/utils.rs @@ -592,12 +592,11 @@ pub(super) enum SubdiagnosticKind { pub(super) struct SubdiagnosticVariant { pub(super) kind: SubdiagnosticKind, pub(super) slug: Option, - pub(super) no_span: bool, } impl SubdiagnosticVariant { /// Constructs a `SubdiagnosticVariant` from a field or type attribute such as `#[note]`, - /// `#[error(parser::add_paren, no_span)]` or `#[suggestion(code = "...")]`. Returns the + /// `#[error(parser::add_paren)]` or `#[suggestion(code = "...")]`. Returns the /// `SubdiagnosticKind` and the diagnostic slug, if specified. pub(super) fn from_attr( attr: &Attribute, @@ -681,7 +680,7 @@ pub(super) fn from_attr( | SubdiagnosticKind::HelpOnce | SubdiagnosticKind::Warn | SubdiagnosticKind::MultipartSuggestion { .. } => { - return Ok(Some(SubdiagnosticVariant { kind, slug: None, no_span: false })); + return Ok(Some(SubdiagnosticVariant { kind, slug: None })); } SubdiagnosticKind::Suggestion { .. } => { throw_span_err!(span, "suggestion without `code = \"...\"`") @@ -697,7 +696,6 @@ pub(super) fn from_attr( let mut suggestion_kind = None; let mut slug = None; - let mut no_span = false; list.parse_args_with(|input: ParseStream<'_>| { let mut is_first = true; @@ -716,7 +714,6 @@ pub(super) fn from_attr( is_first = false; match (arg_name.require_ident()?.to_string().as_str(), &mut kind) { - // ("no_span", _) => no_span = true, ("code", SubdiagnosticKind::Suggestion { code_field, .. }) => { let code_init = build_suggestion_code( &code_field, @@ -762,7 +759,7 @@ pub(super) fn from_attr( (_, SubdiagnosticKind::Suggestion { .. }) => { span_err(arg_name_span, "invalid nested attribute") .help( - "only `no_span`, `style`, `code` and `applicability` are valid nested attributes", + "only `style`, `code` and `applicability` are valid nested attributes", ) .emit(); // Consume the rest of the input to avoid spamming errors @@ -770,13 +767,13 @@ pub(super) fn from_attr( } (_, SubdiagnosticKind::MultipartSuggestion { .. }) => { span_err(arg_name_span, "invalid nested attribute") - .help("only `no_span`, `style` and `applicability` are valid nested attributes") + .help("only `style` and `applicability` are valid nested attributes") .emit(); // Consume the rest of the input to avoid spamming errors let _ = input.parse::(); } _ => { - span_err(arg_name_span, "only `no_span` is a valid nested attribute").emit(); + span_err(arg_name_span, "no nested attribute expected here").emit(); // Consume the rest of the input to avoid spamming errors let _ = input.parse::(); } @@ -821,7 +818,7 @@ pub(super) fn from_attr( | SubdiagnosticKind::Warn => {} } - Ok(Some(SubdiagnosticVariant { kind, slug, no_span })) + Ok(Some(SubdiagnosticVariant { kind, slug })) } } diff --git a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs index 72b414362c72..798eca68b1c9 100644 --- a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs +++ b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs @@ -539,7 +539,7 @@ struct LabelWithTrailingPath { #[diag(no_crate_example, code = E0123)] struct LabelWithTrailingNameValue { #[label(no_crate_label, foo = "...")] - //~^ ERROR only `no_span` is a valid nested attribute + //~^ ERROR no nested attribute expected here span: Span, } @@ -547,7 +547,7 @@ struct LabelWithTrailingNameValue { #[diag(no_crate_example, code = E0123)] struct LabelWithTrailingList { #[label(no_crate_label, foo("..."))] - //~^ ERROR only `no_span` is a valid nested attribute + //~^ ERROR no nested attribute expected here span: Span, } diff --git a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr index 3ccf89cedec7..9ecb6c15767e 100644 --- a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr +++ b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr @@ -192,7 +192,7 @@ error: derive(Diagnostic): invalid nested attribute LL | #[suggestion(nonsense = "bar")] | ^^^^^^^^ | - = help: only `no_span`, `style`, `code` and `applicability` are valid nested attributes + = help: only `style`, `code` and `applicability` are valid nested attributes error: derive(Diagnostic): suggestion without `code = "..."` --> $DIR/diagnostic-derive.rs:235:5 @@ -206,7 +206,7 @@ error: derive(Diagnostic): invalid nested attribute LL | #[suggestion(msg = "bar")] | ^^^ | - = help: only `no_span`, `style`, `code` and `applicability` are valid nested attributes + = help: only `style`, `code` and `applicability` are valid nested attributes error: derive(Diagnostic): suggestion without `code = "..."` --> $DIR/diagnostic-derive.rs:244:5 @@ -282,13 +282,13 @@ error: derive(Diagnostic): a diagnostic slug must be the first argument to the a LL | #[label(no_crate_label, foo)] | ^^^ -error: derive(Diagnostic): only `no_span` is a valid nested attribute +error: derive(Diagnostic): no nested attribute expected here --> $DIR/diagnostic-derive.rs:541:29 | LL | #[label(no_crate_label, foo = "...")] | ^^^ -error: derive(Diagnostic): only `no_span` is a valid nested attribute +error: derive(Diagnostic): no nested attribute expected here --> $DIR/diagnostic-derive.rs:549:29 | LL | #[label(no_crate_label, foo("..."))] diff --git a/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs b/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs index 578fc728de53..b2e7b4c61daa 100644 --- a/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs +++ b/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs @@ -85,7 +85,7 @@ struct F { #[derive(Subdiagnostic)] #[label(bug = "...")] -//~^ ERROR only `no_span` is a valid nested attribute +//~^ ERROR no nested attribute expected here //~| ERROR diagnostic slug must be first argument struct G { #[primary_span] @@ -104,7 +104,7 @@ struct H { #[derive(Subdiagnostic)] #[label(slug = 4)] -//~^ ERROR only `no_span` is a valid nested attribute +//~^ ERROR no nested attribute expected here //~| ERROR diagnostic slug must be first argument struct J { #[primary_span] @@ -114,7 +114,7 @@ struct J { #[derive(Subdiagnostic)] #[label(slug("..."))] -//~^ ERROR only `no_span` is a valid nested attribute +//~^ ERROR no nested attribute expected here //~| ERROR diagnostic slug must be first argument struct K { #[primary_span] @@ -133,7 +133,7 @@ struct M { #[derive(Subdiagnostic)] #[label(no_crate_example, code = "...")] -//~^ ERROR only `no_span` is a valid nested attribute +//~^ ERROR no nested attribute expected here struct N { #[primary_span] span: Span, @@ -142,7 +142,7 @@ struct N { #[derive(Subdiagnostic)] #[label(no_crate_example, applicability = "machine-applicable")] -//~^ ERROR only `no_span` is a valid nested attribute +//~^ ERROR no nested attribute expected here struct O { #[primary_span] span: Span, @@ -214,7 +214,7 @@ enum T { enum U { #[label(code = "...")] //~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute - //~| ERROR only `no_span` is a valid nested attribute + //~| ERROR no nested attribute expected here A { #[primary_span] span: Span, diff --git a/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr b/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr index 568d75d838fe..63634741e934 100644 --- a/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr +++ b/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr @@ -22,7 +22,7 @@ error: derive(Diagnostic): `#[label = ...]` is not a valid attribute LL | #[label = "..."] | ^ -error: derive(Diagnostic): only `no_span` is a valid nested attribute +error: derive(Diagnostic): no nested attribute expected here --> $DIR/subdiagnostic-derive.rs:87:9 | LL | #[label(bug = "...")] @@ -40,7 +40,7 @@ error: expected identifier LL | #[label("...")] | ^^^^^ -error: derive(Diagnostic): only `no_span` is a valid nested attribute +error: derive(Diagnostic): no nested attribute expected here --> $DIR/subdiagnostic-derive.rs:106:9 | LL | #[label(slug = 4)] @@ -52,7 +52,7 @@ error: derive(Diagnostic): diagnostic slug must be first argument of a `#[label( LL | #[label(slug = 4)] | ^ -error: derive(Diagnostic): only `no_span` is a valid nested attribute +error: derive(Diagnostic): no nested attribute expected here --> $DIR/subdiagnostic-derive.rs:116:9 | LL | #[label(slug("..."))] @@ -70,13 +70,13 @@ error: derive(Diagnostic): diagnostic slug must be first argument of a `#[label( LL | #[label()] | ^ -error: derive(Diagnostic): only `no_span` is a valid nested attribute +error: derive(Diagnostic): no nested attribute expected here --> $DIR/subdiagnostic-derive.rs:135:27 | LL | #[label(no_crate_example, code = "...")] | ^^^^ -error: derive(Diagnostic): only `no_span` is a valid nested attribute +error: derive(Diagnostic): no nested attribute expected here --> $DIR/subdiagnostic-derive.rs:144:27 | LL | #[label(no_crate_example, applicability = "machine-applicable")] @@ -112,7 +112,7 @@ error: derive(Diagnostic): `#[bar(...)]` is not a valid attribute LL | #[bar("...")] | ^ -error: derive(Diagnostic): only `no_span` is a valid nested attribute +error: derive(Diagnostic): no nested attribute expected here --> $DIR/subdiagnostic-derive.rs:215:13 | LL | #[label(code = "...")] @@ -292,7 +292,7 @@ error: derive(Diagnostic): invalid nested attribute LL | #[multipart_suggestion(no_crate_example, code = "...", applicability = "machine-applicable")] | ^^^^ | - = help: only `no_span`, `style` and `applicability` are valid nested attributes + = help: only `style` and `applicability` are valid nested attributes error: derive(Diagnostic): multipart suggestion without any `#[suggestion_part(...)]` fields --> $DIR/subdiagnostic-derive.rs:530:1