diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-06-27 15:04:56 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-27 15:04:56 +0200 |
| commit | 8e5fd99b33fb60e96f7c7420c39e95d9807b498e (patch) | |
| tree | 1fb6e54500f9b8cc7846d07282ec62b78f1e37b7 | |
| parent | 8256a75fffc1a744d3e7771b763fab9b04493f1a (diff) | |
| parent | d1f313649ce215c9b0442354ec6aa03384d7101c (diff) | |
| download | rust-8e5fd99b33fb60e96f7c7420c39e95d9807b498e.tar.gz rust-8e5fd99b33fb60e96f7c7420c39e95d9807b498e.zip | |
Rollup merge of #143060 - xizheyin:simplify-diag, r=oli-obk
Only args in main diag are saved and restored without removing the newly added ones cc rust-lang/rust#142724 Here's a more simplified approach, since we'll be storing and restoring the main diagnostic's arg, removing args newly added isn't needed in the derive subdiagnostic implementation. `remove_arg` is helpful only for manual implementation of subdiagnostic. r? ``@oli-obk``
| -rw-r--r-- | compiler/rustc_macros/src/diagnostics/subdiagnostic.rs | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs index 04fdada8024..dcd0116d804 100644 --- a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs @@ -220,7 +220,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { } /// Generates the code for a field with no attributes. - fn generate_field_arg(&mut self, binding_info: &BindingInfo<'_>) -> (TokenStream, TokenStream) { + fn generate_field_arg(&mut self, binding_info: &BindingInfo<'_>) -> TokenStream { let diag = &self.parent.diag; let field = binding_info.ast(); @@ -230,16 +230,12 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { let ident = field.ident.as_ref().unwrap(); let ident = format_ident!("{}", ident); // strip `r#` prefix, if present - let args = quote! { + quote! { #diag.arg( stringify!(#ident), #field_binding ); - }; - let remove_args = quote! { - #diag.remove_arg(stringify!(#ident)); - }; - (args, remove_args) + } } /// Generates the necessary code for all attributes on a field. @@ -610,7 +606,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { let restore_args = quote! { #diag.restore_args(); }; - let (plain_args, remove_args): (TokenStream, TokenStream) = self + let plain_args: TokenStream = self .variant .bindings() .iter() @@ -623,9 +619,8 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { // For #[derive(Subdiagnostic)] // // - Store args of the main diagnostic for later restore. - // - add args of subdiagnostic. + // - Add args of subdiagnostic. // - Generate the calls, such as note, label, etc. - // - Remove the arguments for allowing Vec<Subdiagnostic> to be used. // - Restore the arguments for allowing main and subdiagnostic share the same fields. Ok(quote! { #init @@ -634,7 +629,6 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { #store_args #plain_args #calls - #remove_args #restore_args }) } |
