Move codec module back into middle
This commit is contained in:
parent
6438b9eca8
commit
19c84c8812
16 changed files with 129 additions and 187 deletions
|
@ -6,16 +6,11 @@ use syn::spanned::Spanned;
|
|||
pub(super) fn type_decodable_derive(
|
||||
mut s: synstructure::Structure<'_>,
|
||||
) -> proc_macro2::TokenStream {
|
||||
if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
|
||||
s.add_impl_generic(parse_quote! { 'tcx });
|
||||
}
|
||||
let decoder_ty = quote! { __D };
|
||||
let bound = if s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
|
||||
quote! { <I = ::rustc_middle::ty::TyCtxt<'tcx>> }
|
||||
} else if s.ast().generics.type_params().any(|ty| ty.ident == "I") {
|
||||
quote! { <I = I> }
|
||||
} else {
|
||||
quote! {}
|
||||
};
|
||||
|
||||
s.add_impl_generic(parse_quote! { #decoder_ty: ::rustc_middle::ty::codec::TyDecoder #bound });
|
||||
s.add_impl_generic(parse_quote! { #decoder_ty: ::rustc_middle::ty::codec::TyDecoder<'tcx> });
|
||||
s.add_bounds(synstructure::AddBounds::Fields);
|
||||
s.underscore_const(true);
|
||||
|
||||
|
@ -132,16 +127,11 @@ fn decode_field(field: &syn::Field) -> proc_macro2::TokenStream {
|
|||
pub(super) fn type_encodable_derive(
|
||||
mut s: synstructure::Structure<'_>,
|
||||
) -> proc_macro2::TokenStream {
|
||||
let bound = if s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
|
||||
quote! { <I = ::rustc_middle::ty::TyCtxt<'tcx>> }
|
||||
} else if s.ast().generics.type_params().any(|ty| ty.ident == "I") {
|
||||
quote! { <I = I> }
|
||||
} else {
|
||||
quote! {}
|
||||
};
|
||||
|
||||
let encoder_ty = quote! { __E };
|
||||
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_middle::ty::codec::TyEncoder #bound });
|
||||
if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
|
||||
s.add_impl_generic(parse_quote! { 'tcx });
|
||||
}
|
||||
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_middle::ty::codec::TyEncoder<'tcx> });
|
||||
s.add_bounds(synstructure::AddBounds::Fields);
|
||||
s.underscore_const(true);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue