@@ -6,16 +6,11 @@ use syn::spanned::Spanned;
66pub ( super ) fn type_decodable_derive (
77 mut s : synstructure:: Structure < ' _ > ,
88) -> proc_macro2:: TokenStream {
9+ if !s. ast ( ) . generics . lifetimes ( ) . any ( |lt| lt. lifetime . ident == "tcx" ) {
10+ s. add_impl_generic ( parse_quote ! { ' tcx } ) ;
11+ }
912 let decoder_ty = quote ! { __D } ;
10- let bound = if s. ast ( ) . generics . lifetimes ( ) . any ( |lt| lt. lifetime . ident == "tcx" ) {
11- quote ! { <I = :: rustc_middle:: ty:: TyCtxt <' tcx>> }
12- } else if s. ast ( ) . generics . type_params ( ) . any ( |ty| ty. ident == "I" ) {
13- quote ! { <I = I > }
14- } else {
15- quote ! { }
16- } ;
17-
18- s. add_impl_generic ( parse_quote ! { #decoder_ty: :: rustc_middle:: ty:: codec:: TyDecoder #bound } ) ;
13+ s. add_impl_generic ( parse_quote ! { #decoder_ty: :: rustc_middle:: ty:: codec:: TyDecoder <' tcx> } ) ;
1914 s. add_bounds ( synstructure:: AddBounds :: Fields ) ;
2015 s. underscore_const ( true ) ;
2116
@@ -132,16 +127,11 @@ fn decode_field(field: &syn::Field) -> proc_macro2::TokenStream {
132127pub ( super ) fn type_encodable_derive (
133128 mut s : synstructure:: Structure < ' _ > ,
134129) -> proc_macro2:: TokenStream {
135- let bound = if s. ast ( ) . generics . lifetimes ( ) . any ( |lt| lt. lifetime . ident == "tcx" ) {
136- quote ! { <I = :: rustc_middle:: ty:: TyCtxt <' tcx>> }
137- } else if s. ast ( ) . generics . type_params ( ) . any ( |ty| ty. ident == "I" ) {
138- quote ! { <I = I > }
139- } else {
140- quote ! { }
141- } ;
142-
143130 let encoder_ty = quote ! { __E } ;
144- s. add_impl_generic ( parse_quote ! { #encoder_ty: :: rustc_middle:: ty:: codec:: TyEncoder #bound } ) ;
131+ if !s. ast ( ) . generics . lifetimes ( ) . any ( |lt| lt. lifetime . ident == "tcx" ) {
132+ s. add_impl_generic ( parse_quote ! { ' tcx } ) ;
133+ }
134+ s. add_impl_generic ( parse_quote ! { #encoder_ty: :: rustc_middle:: ty:: codec:: TyEncoder <' tcx> } ) ;
145135 s. add_bounds ( synstructure:: AddBounds :: Fields ) ;
146136 s. underscore_const ( true ) ;
147137
0 commit comments