@@ -15,8 +15,14 @@ mod zeroize;
1515#[ cfg( feature = "zeroize" ) ]
1616mod zeroize_on_drop;
1717
18+ use std:: borrow:: Cow ;
19+
1820use proc_macro2:: { Span , TokenStream } ;
19- use syn:: { punctuated:: Punctuated , spanned:: Spanned , Meta , Path , Result , Token , TypeParamBound } ;
21+ use quote:: quote;
22+ use syn:: {
23+ punctuated:: Punctuated , spanned:: Spanned , Ident , ImplGenerics , Meta , Path , Result , Token ,
24+ TypeGenerics , TypeParamBound , WhereClause ,
25+ } ;
2026
2127use crate :: { Data , DeriveTrait , DeriveWhere , Error , Item , SplitGenerics } ;
2228
@@ -127,8 +133,17 @@ impl TraitImpl for Trait {
127133 self . implementation ( ) . additional_impl ( trait_)
128134 }
129135
130- fn impl_path ( & self , trait_ : & DeriveTrait ) -> Path {
131- self . implementation ( ) . impl_path ( trait_)
136+ fn impl_item (
137+ & self ,
138+ trait_ : & DeriveTrait ,
139+ imp : & ImplGenerics < ' _ > ,
140+ ident : & Ident ,
141+ ty : & TypeGenerics < ' _ > ,
142+ where_clause : & Option < Cow < ' _ , WhereClause > > ,
143+ body : TokenStream ,
144+ ) -> TokenStream {
145+ self . implementation ( )
146+ . impl_item ( trait_, imp, ident, ty, where_clause, body)
132147 }
133148
134149 fn build_signature (
@@ -189,8 +204,25 @@ pub trait TraitImpl {
189204
190205 /// Trait to implement. Only used for [`ZeroizeOnDrop`](https://docs.rs/zeroize/latest/zeroize/trait.ZeroizeOnDrop.html)
191206 /// because it implements [`Drop`] and not itself.
192- fn impl_path ( & self , trait_ : & DeriveTrait ) -> Path {
193- trait_. path ( )
207+ fn impl_item (
208+ & self ,
209+ trait_ : & DeriveTrait ,
210+ imp : & ImplGenerics < ' _ > ,
211+ ident : & Ident ,
212+ ty : & TypeGenerics < ' _ > ,
213+ where_clause : & Option < Cow < ' _ , WhereClause > > ,
214+ body : TokenStream ,
215+ ) -> TokenStream {
216+ let path = trait_. path ( ) ;
217+
218+ quote ! {
219+ #[ automatically_derived]
220+ impl #imp #path for #ident #ty
221+ #where_clause
222+ {
223+ #body
224+ }
225+ }
194226 }
195227
196228 /// Build method signature for this [`Trait`].
0 commit comments