Remove unused no_span option

This commit is contained in:
Jonathan Brouwer
2026-01-25 22:41:56 +01:00
parent 5d21a21695
commit 0bf3f5d51c
7 changed files with 33 additions and 45 deletions
@@ -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
@@ -188,13 +188,11 @@ fn from_iter<T: IntoIterator<Item = &'a SubdiagnosticKind>>(kinds: T) -> Self {
}
impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
fn identify_kind(
&mut self,
) -> Result<Vec<(SubdiagnosticKind, Path, bool)>, DiagnosticDeriveError> {
fn identify_kind(&mut self) -> Result<Vec<(SubdiagnosticKind, Path)>, 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<TokenStream, DiagnosticDeriveError> {
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<TokenStream, DiagnosticDeriveErro
let diag = &self.parent.diag;
let mut calls = TokenStream::new();
for (kind, slug, no_span) in kind_slugs {
for (kind, slug) in kind_slugs {
let message = format_ident!("__message");
calls.extend(
quote! { let #message = #diag.eagerly_translate(crate::fluent_generated::#slug); },
);
let name = format_ident!(
"{}{}",
if span_field.is_some() && !no_span { "span_" } else { "" },
kind
);
let name = format_ident!("{}{}", if span_field.is_some() { "span_" } else { "" }, kind);
let call = match kind {
SubdiagnosticKind::Suggestion {
suggestion_kind,
@@ -601,9 +594,7 @@ pub(crate) fn into_tokens(&mut self) -> Result<TokenStream, DiagnosticDeriveErro
}
}
_ => {
if let Some(span) = span_field
&& !no_span
{
if let Some(span) = span_field {
quote! { #diag.#name(#span, #message); }
} else {
quote! { #diag.#name(#message); }
@@ -592,12 +592,11 @@ pub(super) enum SubdiagnosticKind {
pub(super) struct SubdiagnosticVariant {
pub(super) kind: SubdiagnosticKind,
pub(super) slug: Option<Path>,
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::<TokenStream>();
}
_ => {
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::<TokenStream>();
}
@@ -821,7 +818,7 @@ pub(super) fn from_attr(
| SubdiagnosticKind::Warn => {}
}
Ok(Some(SubdiagnosticVariant { kind, slug, no_span }))
Ok(Some(SubdiagnosticVariant { kind, slug }))
}
}
@@ -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,
}
@@ -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("..."))]
@@ -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,
@@ -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