Skip to content

Commit fbf8b93

Browse files
committed
Auto merge of #105233 - mejrs:always_eager, r=estebank
Always evaluate vecs of subdiagnostics eagerly See https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20lists!/near/310186705 for context
2 parents ba64ba8 + a7838d8 commit fbf8b93

File tree

6 files changed

+48
-57
lines changed

6 files changed

+48
-57
lines changed

compiler/rustc_infer/src/errors/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,6 @@ pub struct MismatchedStaticLifetime<'a> {
517517
pub expl: Option<note_and_explain::RegionExplanation<'a>>,
518518
#[subdiagnostic]
519519
pub does_not_outlive_static_from_impl: DoesNotOutliveStaticFromImpl,
520-
#[subdiagnostic(eager)]
520+
#[subdiagnostic]
521521
pub implicit_static_lifetimes: Vec<ImplicitStaticLifetimeSubdiag>,
522522
}

compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs

+11-36
Original file line numberDiff line numberDiff line change
@@ -372,46 +372,21 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
372372
}
373373
}
374374
(Meta::Path(_), "subdiagnostic") => {
375-
return Ok(quote! { #diag.subdiagnostic(#binding); });
375+
if FieldInnerTy::from_type(&info.binding.ast().ty).will_iterate() {
376+
let DiagnosticDeriveKind::Diagnostic { handler } = &self.parent.kind else {
377+
// No eager translation for lints.
378+
return Ok(quote! { #diag.subdiagnostic(#binding); });
379+
};
380+
return Ok(quote! { #diag.eager_subdiagnostic(#handler, #binding); });
381+
} else {
382+
return Ok(quote! { #diag.subdiagnostic(#binding); });
383+
}
376384
}
377-
(Meta::NameValue(_), "subdiagnostic") => {
385+
(Meta::List(_), "subdiagnostic") => {
378386
throw_invalid_attr!(attr, &meta, |diag| {
379-
diag.help("`eager` is the only supported nested attribute for `subdiagnostic`")
387+
diag.help("`subdiagnostic` does not support nested attributes")
380388
})
381389
}
382-
(Meta::List(MetaList { ref nested, .. }), "subdiagnostic") => {
383-
if nested.len() != 1 {
384-
throw_invalid_attr!(attr, &meta, |diag| {
385-
diag.help(
386-
"`eager` is the only supported nested attribute for `subdiagnostic`",
387-
)
388-
})
389-
}
390-
391-
let handler = match &self.parent.kind {
392-
DiagnosticDeriveKind::Diagnostic { handler } => handler,
393-
DiagnosticDeriveKind::LintDiagnostic => {
394-
throw_invalid_attr!(attr, &meta, |diag| {
395-
diag.help("eager subdiagnostics are not supported on lints")
396-
})
397-
}
398-
};
399-
400-
let nested_attr = nested.first().expect("pop failed for single element list");
401-
match nested_attr {
402-
NestedMeta::Meta(meta @ Meta::Path(_))
403-
if meta.path().segments.last().unwrap().ident.to_string().as_str()
404-
== "eager" =>
405-
{
406-
return Ok(quote! { #diag.eager_subdiagnostic(#handler, #binding); });
407-
}
408-
_ => {
409-
throw_invalid_nested_attr!(attr, nested_attr, |diag| {
410-
diag.help("`eager` is the only supported nested attribute for `subdiagnostic`")
411-
})
412-
}
413-
}
414-
}
415390
_ => (),
416391
}
417392

compiler/rustc_query_system/src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub struct Cycle {
4949
#[primary_span]
5050
pub span: Span,
5151
pub stack_bottom: String,
52-
#[subdiagnostic(eager)]
52+
#[subdiagnostic]
5353
pub cycle_stack: Vec<CycleStack>,
5454
#[subdiagnostic]
5555
pub stack_count: StackCount,

compiler/rustc_session/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl ExprParenthesesNeeded {
176176
#[derive(Diagnostic)]
177177
#[diag(session_skipping_const_checks)]
178178
pub struct SkippingConstChecks {
179-
#[subdiagnostic(eager)]
179+
#[subdiagnostic]
180180
pub unleashed_features: Vec<UnleashedFeatureHelp>,
181181
}
182182

src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ struct RawIdentDiagnosticArg {
683683
#[diag(compiletest_example)]
684684
struct SubdiagnosticBad {
685685
#[subdiagnostic(bad)]
686-
//~^ ERROR `#[subdiagnostic(bad)]` is not a valid attribute
686+
//~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
687687
note: Note,
688688
}
689689

@@ -707,7 +707,7 @@ struct SubdiagnosticBadTwice {
707707
#[diag(compiletest_example)]
708708
struct SubdiagnosticBadLitStr {
709709
#[subdiagnostic("bad")]
710-
//~^ ERROR `#[subdiagnostic("...")]` is not a valid attribute
710+
//~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
711711
note: Note,
712712
}
713713

@@ -723,6 +723,7 @@ struct SubdiagnosticEagerLint {
723723
#[diag(compiletest_example)]
724724
struct SubdiagnosticEagerCorrect {
725725
#[subdiagnostic(eager)]
726+
//~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
726727
note: Note,
727728
}
728729

@@ -743,6 +744,7 @@ pub(crate) struct SubdiagnosticWithSuggestion {
743744
#[diag(compiletest_example)]
744745
struct SubdiagnosticEagerSuggestion {
745746
#[subdiagnostic(eager)]
747+
//~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
746748
sub: SubdiagnosticWithSuggestion,
747749
}
748750

src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr

+30-16
Original file line numberDiff line numberDiff line change
@@ -533,60 +533,74 @@ LL | #[label]
533533
|
534534
= help: `#[label]` and `#[suggestion]` can only be applied to fields
535535

536-
error: `#[subdiagnostic(bad)]` is not a valid attribute
537-
--> $DIR/diagnostic-derive.rs:685:21
536+
error: `#[subdiagnostic(...)]` is not a valid attribute
537+
--> $DIR/diagnostic-derive.rs:685:5
538538
|
539539
LL | #[subdiagnostic(bad)]
540-
| ^^^
540+
| ^^^^^^^^^^^^^^^^^^^^^
541541
|
542-
= help: `eager` is the only supported nested attribute for `subdiagnostic`
542+
= help: `subdiagnostic` does not support nested attributes
543543

544544
error: `#[subdiagnostic = ...]` is not a valid attribute
545545
--> $DIR/diagnostic-derive.rs:693:5
546546
|
547547
LL | #[subdiagnostic = "bad"]
548548
| ^^^^^^^^^^^^^^^^^^^^^^^^
549-
|
550-
= help: `eager` is the only supported nested attribute for `subdiagnostic`
551549

552550
error: `#[subdiagnostic(...)]` is not a valid attribute
553551
--> $DIR/diagnostic-derive.rs:701:5
554552
|
555553
LL | #[subdiagnostic(bad, bad)]
556554
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
557555
|
558-
= help: `eager` is the only supported nested attribute for `subdiagnostic`
556+
= help: `subdiagnostic` does not support nested attributes
559557

560-
error: `#[subdiagnostic("...")]` is not a valid attribute
561-
--> $DIR/diagnostic-derive.rs:709:21
558+
error: `#[subdiagnostic(...)]` is not a valid attribute
559+
--> $DIR/diagnostic-derive.rs:709:5
562560
|
563561
LL | #[subdiagnostic("bad")]
564-
| ^^^^^
562+
| ^^^^^^^^^^^^^^^^^^^^^^^
565563
|
566-
= help: `eager` is the only supported nested attribute for `subdiagnostic`
564+
= help: `subdiagnostic` does not support nested attributes
567565

568566
error: `#[subdiagnostic(...)]` is not a valid attribute
569567
--> $DIR/diagnostic-derive.rs:717:5
570568
|
571569
LL | #[subdiagnostic(eager)]
572570
| ^^^^^^^^^^^^^^^^^^^^^^^
573571
|
574-
= help: eager subdiagnostics are not supported on lints
572+
= help: `subdiagnostic` does not support nested attributes
573+
574+
error: `#[subdiagnostic(...)]` is not a valid attribute
575+
--> $DIR/diagnostic-derive.rs:725:5
576+
|
577+
LL | #[subdiagnostic(eager)]
578+
| ^^^^^^^^^^^^^^^^^^^^^^^
579+
|
580+
= help: `subdiagnostic` does not support nested attributes
581+
582+
error: `#[subdiagnostic(...)]` is not a valid attribute
583+
--> $DIR/diagnostic-derive.rs:746:5
584+
|
585+
LL | #[subdiagnostic(eager)]
586+
| ^^^^^^^^^^^^^^^^^^^^^^^
587+
|
588+
= help: `subdiagnostic` does not support nested attributes
575589

576590
error: expected at least one string literal for `code(...)`
577-
--> $DIR/diagnostic-derive.rs:775:18
591+
--> $DIR/diagnostic-derive.rs:777:18
578592
|
579593
LL | #[suggestion(code())]
580594
| ^^^^^^
581595

582596
error: `code(...)` must contain only string literals
583-
--> $DIR/diagnostic-derive.rs:783:23
597+
--> $DIR/diagnostic-derive.rs:785:23
584598
|
585599
LL | #[suggestion(code(foo))]
586600
| ^^^
587601

588602
error: `code = "..."`/`code(...)` must contain only string literals
589-
--> $DIR/diagnostic-derive.rs:791:18
603+
--> $DIR/diagnostic-derive.rs:793:18
590604
|
591605
LL | #[suggestion(code = 3)]
592606
| ^^^^^^^^
@@ -662,7 +676,7 @@ note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg`
662676
--> $COMPILER_DIR/rustc_errors/src/diagnostic_builder.rs:LL:CC
663677
= note: this error originates in the derive macro `Diagnostic` which comes from the expansion of the macro `forward` (in Nightly builds, run with -Z macro-backtrace for more info)
664678

665-
error: aborting due to 83 previous errors
679+
error: aborting due to 85 previous errors
666680

667681
Some errors have detailed explanations: E0277, E0425.
668682
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)