diff options
| author | mejrs <> | 2023-01-09 00:00:41 +0100 |
|---|---|---|
| committer | David Tolnay <dtolnay@gmail.com> | 2023-01-11 14:20:34 -0800 |
| commit | 7aff210ead0eba3b4c6e6b2cbae5157e1ffe0562 (patch) | |
| tree | 0ce1ddd20d6bf5b093f945a1e685d06eeb2ab0ca /compiler/rustc_macros/src | |
| parent | ef4046e4f3932991971cdb64915172899532aece (diff) | |
| download | rust-7aff210ead0eba3b4c6e6b2cbae5157e1ffe0562.tar.gz rust-7aff210ead0eba3b4c6e6b2cbae5157e1ffe0562.zip | |
Support eager subdiagnostics again
Diffstat (limited to 'compiler/rustc_macros/src')
| -rw-r--r-- | compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs | 24 | ||||
| -rw-r--r-- | compiler/rustc_macros/src/lib.rs | 1 |
2 files changed, 21 insertions, 4 deletions
diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs index 82f6812026a..e405462bbb8 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs @@ -382,10 +382,26 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> { return Ok(quote! { #diag.subdiagnostic(#binding); }); } } - (Meta::List(_), "subdiagnostic") => { - throw_invalid_attr!(attr, &meta, |diag| { - diag.help("`subdiagnostic` does not support nested attributes") - }) + (Meta::List(MetaList { ref nested, .. }), "subdiagnostic") => { + if nested.len() == 1 + && let Some(NestedMeta::Meta(Meta::Path(path))) = nested.first() + && path.is_ident("eager") { + 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") + }) + } + }; + return Ok(quote! { #diag.eager_subdiagnostic(#handler, #binding); }); + } else { + throw_invalid_attr!(attr, &meta, |diag| { + diag.help( + "`eager` is the only supported nested attribute for `subdiagnostic`", + ) + }) + } } _ => (), } diff --git a/compiler/rustc_macros/src/lib.rs b/compiler/rustc_macros/src/lib.rs index ac916bb6068..bb3722fe156 100644 --- a/compiler/rustc_macros/src/lib.rs +++ b/compiler/rustc_macros/src/lib.rs @@ -1,5 +1,6 @@ #![feature(allow_internal_unstable)] #![feature(if_let_guard)] +#![feature(let_chains)] #![feature(never_type)] #![feature(proc_macro_diagnostic)] #![feature(proc_macro_span)] |
