Auto merge of #105233 - mejrs:always_eager, r=estebank
Always evaluate vecs of subdiagnostics eagerly
See 310186705
for context
This commit is contained in:
commit
fbf8b937b4
6 changed files with 48 additions and 57 deletions
|
@ -517,6 +517,6 @@ pub struct MismatchedStaticLifetime<'a> {
|
||||||
pub expl: Option<note_and_explain::RegionExplanation<'a>>,
|
pub expl: Option<note_and_explain::RegionExplanation<'a>>,
|
||||||
#[subdiagnostic]
|
#[subdiagnostic]
|
||||||
pub does_not_outlive_static_from_impl: DoesNotOutliveStaticFromImpl,
|
pub does_not_outlive_static_from_impl: DoesNotOutliveStaticFromImpl,
|
||||||
#[subdiagnostic(eager)]
|
#[subdiagnostic]
|
||||||
pub implicit_static_lifetimes: Vec<ImplicitStaticLifetimeSubdiag>,
|
pub implicit_static_lifetimes: Vec<ImplicitStaticLifetimeSubdiag>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -372,46 +372,21 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(Meta::Path(_), "subdiagnostic") => {
|
(Meta::Path(_), "subdiagnostic") => {
|
||||||
return Ok(quote! { #diag.subdiagnostic(#binding); });
|
if FieldInnerTy::from_type(&info.binding.ast().ty).will_iterate() {
|
||||||
|
let DiagnosticDeriveKind::Diagnostic { handler } = &self.parent.kind else {
|
||||||
|
// No eager translation for lints.
|
||||||
|
return Ok(quote! { #diag.subdiagnostic(#binding); });
|
||||||
|
};
|
||||||
|
return Ok(quote! { #diag.eager_subdiagnostic(#handler, #binding); });
|
||||||
|
} else {
|
||||||
|
return Ok(quote! { #diag.subdiagnostic(#binding); });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(Meta::NameValue(_), "subdiagnostic") => {
|
(Meta::List(_), "subdiagnostic") => {
|
||||||
throw_invalid_attr!(attr, &meta, |diag| {
|
throw_invalid_attr!(attr, &meta, |diag| {
|
||||||
diag.help("`eager` is the only supported nested attribute for `subdiagnostic`")
|
diag.help("`subdiagnostic` does not support nested attributes")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
(Meta::List(MetaList { ref nested, .. }), "subdiagnostic") => {
|
|
||||||
if nested.len() != 1 {
|
|
||||||
throw_invalid_attr!(attr, &meta, |diag| {
|
|
||||||
diag.help(
|
|
||||||
"`eager` is the only supported nested attribute for `subdiagnostic`",
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
let handler = match &self.parent.kind {
|
|
||||||
DiagnosticDeriveKind::Diagnostic { handler } => handler,
|
|
||||||
DiagnosticDeriveKind::LintDiagnostic => {
|
|
||||||
throw_invalid_attr!(attr, &meta, |diag| {
|
|
||||||
diag.help("eager subdiagnostics are not supported on lints")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let nested_attr = nested.first().expect("pop failed for single element list");
|
|
||||||
match nested_attr {
|
|
||||||
NestedMeta::Meta(meta @ Meta::Path(_))
|
|
||||||
if meta.path().segments.last().unwrap().ident.to_string().as_str()
|
|
||||||
== "eager" =>
|
|
||||||
{
|
|
||||||
return Ok(quote! { #diag.eager_subdiagnostic(#handler, #binding); });
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
throw_invalid_nested_attr!(attr, nested_attr, |diag| {
|
|
||||||
diag.help("`eager` is the only supported nested attribute for `subdiagnostic`")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ pub struct Cycle {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub stack_bottom: String,
|
pub stack_bottom: String,
|
||||||
#[subdiagnostic(eager)]
|
#[subdiagnostic]
|
||||||
pub cycle_stack: Vec<CycleStack>,
|
pub cycle_stack: Vec<CycleStack>,
|
||||||
#[subdiagnostic]
|
#[subdiagnostic]
|
||||||
pub stack_count: StackCount,
|
pub stack_count: StackCount,
|
||||||
|
|
|
@ -176,7 +176,7 @@ impl ExprParenthesesNeeded {
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(session_skipping_const_checks)]
|
#[diag(session_skipping_const_checks)]
|
||||||
pub struct SkippingConstChecks {
|
pub struct SkippingConstChecks {
|
||||||
#[subdiagnostic(eager)]
|
#[subdiagnostic]
|
||||||
pub unleashed_features: Vec<UnleashedFeatureHelp>,
|
pub unleashed_features: Vec<UnleashedFeatureHelp>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -683,7 +683,7 @@ struct RawIdentDiagnosticArg {
|
||||||
#[diag(compiletest_example)]
|
#[diag(compiletest_example)]
|
||||||
struct SubdiagnosticBad {
|
struct SubdiagnosticBad {
|
||||||
#[subdiagnostic(bad)]
|
#[subdiagnostic(bad)]
|
||||||
//~^ ERROR `#[subdiagnostic(bad)]` is not a valid attribute
|
//~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
|
||||||
note: Note,
|
note: Note,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -707,7 +707,7 @@ struct SubdiagnosticBadTwice {
|
||||||
#[diag(compiletest_example)]
|
#[diag(compiletest_example)]
|
||||||
struct SubdiagnosticBadLitStr {
|
struct SubdiagnosticBadLitStr {
|
||||||
#[subdiagnostic("bad")]
|
#[subdiagnostic("bad")]
|
||||||
//~^ ERROR `#[subdiagnostic("...")]` is not a valid attribute
|
//~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
|
||||||
note: Note,
|
note: Note,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -723,6 +723,7 @@ struct SubdiagnosticEagerLint {
|
||||||
#[diag(compiletest_example)]
|
#[diag(compiletest_example)]
|
||||||
struct SubdiagnosticEagerCorrect {
|
struct SubdiagnosticEagerCorrect {
|
||||||
#[subdiagnostic(eager)]
|
#[subdiagnostic(eager)]
|
||||||
|
//~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
|
||||||
note: Note,
|
note: Note,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -743,6 +744,7 @@ pub(crate) struct SubdiagnosticWithSuggestion {
|
||||||
#[diag(compiletest_example)]
|
#[diag(compiletest_example)]
|
||||||
struct SubdiagnosticEagerSuggestion {
|
struct SubdiagnosticEagerSuggestion {
|
||||||
#[subdiagnostic(eager)]
|
#[subdiagnostic(eager)]
|
||||||
|
//~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
|
||||||
sub: SubdiagnosticWithSuggestion,
|
sub: SubdiagnosticWithSuggestion,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -533,21 +533,19 @@ LL | #[label]
|
||||||
|
|
|
|
||||||
= help: `#[label]` and `#[suggestion]` can only be applied to fields
|
= help: `#[label]` and `#[suggestion]` can only be applied to fields
|
||||||
|
|
||||||
error: `#[subdiagnostic(bad)]` is not a valid attribute
|
error: `#[subdiagnostic(...)]` is not a valid attribute
|
||||||
--> $DIR/diagnostic-derive.rs:685:21
|
--> $DIR/diagnostic-derive.rs:685:5
|
||||||
|
|
|
|
||||||
LL | #[subdiagnostic(bad)]
|
LL | #[subdiagnostic(bad)]
|
||||||
| ^^^
|
| ^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= help: `eager` is the only supported nested attribute for `subdiagnostic`
|
= help: `subdiagnostic` does not support nested attributes
|
||||||
|
|
||||||
error: `#[subdiagnostic = ...]` is not a valid attribute
|
error: `#[subdiagnostic = ...]` is not a valid attribute
|
||||||
--> $DIR/diagnostic-derive.rs:693:5
|
--> $DIR/diagnostic-derive.rs:693:5
|
||||||
|
|
|
|
||||||
LL | #[subdiagnostic = "bad"]
|
LL | #[subdiagnostic = "bad"]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
= help: `eager` is the only supported nested attribute for `subdiagnostic`
|
|
||||||
|
|
||||||
error: `#[subdiagnostic(...)]` is not a valid attribute
|
error: `#[subdiagnostic(...)]` is not a valid attribute
|
||||||
--> $DIR/diagnostic-derive.rs:701:5
|
--> $DIR/diagnostic-derive.rs:701:5
|
||||||
|
@ -555,15 +553,15 @@ error: `#[subdiagnostic(...)]` is not a valid attribute
|
||||||
LL | #[subdiagnostic(bad, bad)]
|
LL | #[subdiagnostic(bad, bad)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= help: `eager` is the only supported nested attribute for `subdiagnostic`
|
= help: `subdiagnostic` does not support nested attributes
|
||||||
|
|
||||||
error: `#[subdiagnostic("...")]` is not a valid attribute
|
error: `#[subdiagnostic(...)]` is not a valid attribute
|
||||||
--> $DIR/diagnostic-derive.rs:709:21
|
--> $DIR/diagnostic-derive.rs:709:5
|
||||||
|
|
|
|
||||||
LL | #[subdiagnostic("bad")]
|
LL | #[subdiagnostic("bad")]
|
||||||
| ^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= help: `eager` is the only supported nested attribute for `subdiagnostic`
|
= help: `subdiagnostic` does not support nested attributes
|
||||||
|
|
||||||
error: `#[subdiagnostic(...)]` is not a valid attribute
|
error: `#[subdiagnostic(...)]` is not a valid attribute
|
||||||
--> $DIR/diagnostic-derive.rs:717:5
|
--> $DIR/diagnostic-derive.rs:717:5
|
||||||
|
@ -571,22 +569,38 @@ error: `#[subdiagnostic(...)]` is not a valid attribute
|
||||||
LL | #[subdiagnostic(eager)]
|
LL | #[subdiagnostic(eager)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= help: eager subdiagnostics are not supported on lints
|
= help: `subdiagnostic` does not support nested attributes
|
||||||
|
|
||||||
|
error: `#[subdiagnostic(...)]` is not a valid attribute
|
||||||
|
--> $DIR/diagnostic-derive.rs:725:5
|
||||||
|
|
|
||||||
|
LL | #[subdiagnostic(eager)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= help: `subdiagnostic` does not support nested attributes
|
||||||
|
|
||||||
|
error: `#[subdiagnostic(...)]` is not a valid attribute
|
||||||
|
--> $DIR/diagnostic-derive.rs:746:5
|
||||||
|
|
|
||||||
|
LL | #[subdiagnostic(eager)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= help: `subdiagnostic` does not support nested attributes
|
||||||
|
|
||||||
error: expected at least one string literal for `code(...)`
|
error: expected at least one string literal for `code(...)`
|
||||||
--> $DIR/diagnostic-derive.rs:775:18
|
--> $DIR/diagnostic-derive.rs:777:18
|
||||||
|
|
|
|
||||||
LL | #[suggestion(code())]
|
LL | #[suggestion(code())]
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
||||||
error: `code(...)` must contain only string literals
|
error: `code(...)` must contain only string literals
|
||||||
--> $DIR/diagnostic-derive.rs:783:23
|
--> $DIR/diagnostic-derive.rs:785:23
|
||||||
|
|
|
|
||||||
LL | #[suggestion(code(foo))]
|
LL | #[suggestion(code(foo))]
|
||||||
| ^^^
|
| ^^^
|
||||||
|
|
||||||
error: `code = "..."`/`code(...)` must contain only string literals
|
error: `code = "..."`/`code(...)` must contain only string literals
|
||||||
--> $DIR/diagnostic-derive.rs:791:18
|
--> $DIR/diagnostic-derive.rs:793:18
|
||||||
|
|
|
|
||||||
LL | #[suggestion(code = 3)]
|
LL | #[suggestion(code = 3)]
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
|
@ -662,7 +676,7 @@ note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg`
|
||||||
--> $COMPILER_DIR/rustc_errors/src/diagnostic_builder.rs:LL:CC
|
--> $COMPILER_DIR/rustc_errors/src/diagnostic_builder.rs:LL:CC
|
||||||
= 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)
|
= 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)
|
||||||
|
|
||||||
error: aborting due to 83 previous errors
|
error: aborting due to 85 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0277, E0425.
|
Some errors have detailed explanations: E0277, E0425.
|
||||||
For more information about an error, try `rustc --explain E0277`.
|
For more information about an error, try `rustc --explain E0277`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue