Only args in main diag are saved and restored without removing the newly added ones
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
This commit is contained in:
@@ -220,7 +220,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Generates the code for a field with no attributes.
|
/// 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 diag = &self.parent.diag;
|
||||||
|
|
||||||
let field = binding_info.ast();
|
let field = binding_info.ast();
|
||||||
@@ -230,16 +230,12 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
|
|||||||
let ident = field.ident.as_ref().unwrap();
|
let ident = field.ident.as_ref().unwrap();
|
||||||
let ident = format_ident!("{}", ident); // strip `r#` prefix, if present
|
let ident = format_ident!("{}", ident); // strip `r#` prefix, if present
|
||||||
|
|
||||||
let args = quote! {
|
quote! {
|
||||||
#diag.arg(
|
#diag.arg(
|
||||||
stringify!(#ident),
|
stringify!(#ident),
|
||||||
#field_binding
|
#field_binding
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
let remove_args = quote! {
|
|
||||||
#diag.remove_arg(stringify!(#ident));
|
|
||||||
};
|
|
||||||
(args, remove_args)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates the necessary code for all attributes on a field.
|
/// Generates the necessary code for all attributes on a field.
|
||||||
@@ -610,7 +606,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
|
|||||||
let restore_args = quote! {
|
let restore_args = quote! {
|
||||||
#diag.restore_args();
|
#diag.restore_args();
|
||||||
};
|
};
|
||||||
let (plain_args, remove_args): (TokenStream, TokenStream) = self
|
let plain_args: TokenStream = self
|
||||||
.variant
|
.variant
|
||||||
.bindings()
|
.bindings()
|
||||||
.iter()
|
.iter()
|
||||||
@@ -623,9 +619,8 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
|
|||||||
// For #[derive(Subdiagnostic)]
|
// For #[derive(Subdiagnostic)]
|
||||||
//
|
//
|
||||||
// - Store args of the main diagnostic for later restore.
|
// - 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.
|
// - 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.
|
// - Restore the arguments for allowing main and subdiagnostic share the same fields.
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
#init
|
#init
|
||||||
@@ -634,7 +629,6 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
|
|||||||
#store_args
|
#store_args
|
||||||
#plain_args
|
#plain_args
|
||||||
#calls
|
#calls
|
||||||
#remove_args
|
|
||||||
#restore_args
|
#restore_args
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user