@@ -2655,6 +2655,35 @@ impl Default for FnHeader {
2655
2655
}
2656
2656
}
2657
2657
2658
+ #[ derive( Clone , Encodable , Decodable , Debug ) ]
2659
+ pub struct TraitKind (
2660
+ pub IsAuto ,
2661
+ pub Unsafe ,
2662
+ pub Generics ,
2663
+ pub GenericBounds ,
2664
+ pub Vec < P < AssocItem > > ,
2665
+ ) ;
2666
+ #[ derive( Clone , Encodable , Decodable , Debug ) ]
2667
+ pub struct TyAliasKind ( pub Defaultness , pub Generics , pub GenericBounds , pub Option < P < Ty > > ) ;
2668
+
2669
+ #[ derive( Clone , Encodable , Decodable , Debug ) ]
2670
+ pub struct ImplKind {
2671
+ pub unsafety : Unsafe ,
2672
+ pub polarity : ImplPolarity ,
2673
+ pub defaultness : Defaultness ,
2674
+ pub constness : Const ,
2675
+ pub generics : Generics ,
2676
+
2677
+ /// The trait being implemented, if any.
2678
+ pub of_trait : Option < TraitRef > ,
2679
+
2680
+ pub self_ty : P < Ty > ,
2681
+ pub items : Vec < P < AssocItem > > ,
2682
+ }
2683
+
2684
+ #[ derive( Clone , Encodable , Decodable , Debug ) ]
2685
+ pub struct FnKind ( pub Defaultness , pub FnSig , pub Generics , pub Option < P < Block > > ) ;
2686
+
2658
2687
#[ derive( Clone , Encodable , Decodable , Debug ) ]
2659
2688
pub enum ItemKind {
2660
2689
/// An `extern crate` item, with the optional *original* crate name if the crate was renamed.
@@ -2676,7 +2705,7 @@ pub enum ItemKind {
2676
2705
/// A function declaration (`fn`).
2677
2706
///
2678
2707
/// E.g., `fn foo(bar: usize) -> usize { .. }`.
2679
- Fn ( Defaultness , FnSig , Generics , Option < P < Block > > ) ,
2708
+ Fn ( Box < FnKind > ) ,
2680
2709
/// A module declaration (`mod`).
2681
2710
///
2682
2711
/// E.g., `mod foo;` or `mod foo { .. }`.
@@ -2690,7 +2719,7 @@ pub enum ItemKind {
2690
2719
/// A type alias (`type`).
2691
2720
///
2692
2721
/// E.g., `type Foo = Bar<u8>;`.
2693
- TyAlias ( Defaultness , Generics , GenericBounds , Option < P < Ty > > ) ,
2722
+ TyAlias ( Box < TyAliasKind > ) ,
2694
2723
/// An enum definition (`enum`).
2695
2724
///
2696
2725
/// E.g., `enum Foo<A, B> { C<A>, D<B> }`.
@@ -2706,27 +2735,15 @@ pub enum ItemKind {
2706
2735
/// A trait declaration (`trait`).
2707
2736
///
2708
2737
/// E.g., `trait Foo { .. }`, `trait Foo<T> { .. }` or `auto trait Foo {}`.
2709
- Trait ( IsAuto , Unsafe , Generics , GenericBounds , Vec < P < AssocItem > > ) ,
2738
+ Trait ( Box < TraitKind > ) ,
2710
2739
/// Trait alias
2711
2740
///
2712
2741
/// E.g., `trait Foo = Bar + Quux;`.
2713
2742
TraitAlias ( Generics , GenericBounds ) ,
2714
2743
/// An implementation.
2715
2744
///
2716
2745
/// E.g., `impl<A> Foo<A> { .. }` or `impl<A> Trait for Foo<A> { .. }`.
2717
- Impl {
2718
- unsafety : Unsafe ,
2719
- polarity : ImplPolarity ,
2720
- defaultness : Defaultness ,
2721
- constness : Const ,
2722
- generics : Generics ,
2723
-
2724
- /// The trait being implemented, if any.
2725
- of_trait : Option < TraitRef > ,
2726
-
2727
- self_ty : P < Ty > ,
2728
- items : Vec < P < AssocItem > > ,
2729
- } ,
2746
+ Impl ( Box < ImplKind > ) ,
2730
2747
/// A macro invocation.
2731
2748
///
2732
2749
/// E.g., `foo!(..)`.
@@ -2770,14 +2787,14 @@ impl ItemKind {
2770
2787
2771
2788
pub fn generics ( & self ) -> Option < & Generics > {
2772
2789
match self {
2773
- Self :: Fn ( _, _, generics, _)
2774
- | Self :: TyAlias ( _, generics, ..)
2790
+ Self :: Fn ( box FnKind ( _, _, generics, _) )
2791
+ | Self :: TyAlias ( box TyAliasKind ( _, generics, ..) )
2775
2792
| Self :: Enum ( _, generics)
2776
2793
| Self :: Struct ( _, generics)
2777
2794
| Self :: Union ( _, generics)
2778
- | Self :: Trait ( _, _, generics, ..)
2795
+ | Self :: Trait ( box TraitKind ( _, _, generics, ..) )
2779
2796
| Self :: TraitAlias ( generics, _)
2780
- | Self :: Impl { generics, .. } => Some ( generics) ,
2797
+ | Self :: Impl ( box ImplKind { generics, .. } ) => Some ( generics) ,
2781
2798
_ => None ,
2782
2799
}
2783
2800
}
@@ -2800,17 +2817,19 @@ pub enum AssocItemKind {
2800
2817
/// If `def` is parsed, then the constant is provided, and otherwise required.
2801
2818
Const ( Defaultness , P < Ty > , Option < P < Expr > > ) ,
2802
2819
/// An associated function.
2803
- Fn ( Defaultness , FnSig , Generics , Option < P < Block > > ) ,
2820
+ Fn ( Box < FnKind > ) ,
2804
2821
/// An associated type.
2805
- TyAlias ( Defaultness , Generics , GenericBounds , Option < P < Ty > > ) ,
2822
+ TyAlias ( Box < TyAliasKind > ) ,
2806
2823
/// A macro expanding to associated items.
2807
2824
MacCall ( MacCall ) ,
2808
2825
}
2809
2826
2810
2827
impl AssocItemKind {
2811
2828
pub fn defaultness ( & self ) -> Defaultness {
2812
2829
match * self {
2813
- Self :: Const ( def, ..) | Self :: Fn ( def, ..) | Self :: TyAlias ( def, ..) => def,
2830
+ Self :: Const ( def, ..)
2831
+ | Self :: Fn ( box FnKind ( def, ..) )
2832
+ | Self :: TyAlias ( box TyAliasKind ( def, ..) ) => def,
2814
2833
Self :: MacCall ( ..) => Defaultness :: Final ,
2815
2834
}
2816
2835
}
@@ -2820,8 +2839,8 @@ impl From<AssocItemKind> for ItemKind {
2820
2839
fn from ( assoc_item_kind : AssocItemKind ) -> ItemKind {
2821
2840
match assoc_item_kind {
2822
2841
AssocItemKind :: Const ( a, b, c) => ItemKind :: Const ( a, b, c) ,
2823
- AssocItemKind :: Fn ( a , b , c , d ) => ItemKind :: Fn ( a , b , c , d ) ,
2824
- AssocItemKind :: TyAlias ( a , b , c , d ) => ItemKind :: TyAlias ( a , b , c , d ) ,
2842
+ AssocItemKind :: Fn ( fn_kind ) => ItemKind :: Fn ( fn_kind ) ,
2843
+ AssocItemKind :: TyAlias ( ty_alias_kind ) => ItemKind :: TyAlias ( ty_alias_kind ) ,
2825
2844
AssocItemKind :: MacCall ( a) => ItemKind :: MacCall ( a) ,
2826
2845
}
2827
2846
}
@@ -2833,8 +2852,8 @@ impl TryFrom<ItemKind> for AssocItemKind {
2833
2852
fn try_from ( item_kind : ItemKind ) -> Result < AssocItemKind , ItemKind > {
2834
2853
Ok ( match item_kind {
2835
2854
ItemKind :: Const ( a, b, c) => AssocItemKind :: Const ( a, b, c) ,
2836
- ItemKind :: Fn ( a , b , c , d ) => AssocItemKind :: Fn ( a , b , c , d ) ,
2837
- ItemKind :: TyAlias ( a , b , c , d ) => AssocItemKind :: TyAlias ( a , b , c , d ) ,
2855
+ ItemKind :: Fn ( fn_kind ) => AssocItemKind :: Fn ( fn_kind ) ,
2856
+ ItemKind :: TyAlias ( ty_alias_kind ) => AssocItemKind :: TyAlias ( ty_alias_kind ) ,
2838
2857
ItemKind :: MacCall ( a) => AssocItemKind :: MacCall ( a) ,
2839
2858
_ => return Err ( item_kind) ,
2840
2859
} )
@@ -2846,10 +2865,10 @@ impl TryFrom<ItemKind> for AssocItemKind {
2846
2865
pub enum ForeignItemKind {
2847
2866
/// A foreign static item (`static FOO: u8`).
2848
2867
Static ( P < Ty > , Mutability , Option < P < Expr > > ) ,
2849
- /// A foreign function.
2850
- Fn ( Defaultness , FnSig , Generics , Option < P < Block > > ) ,
2851
- /// A foreign type.
2852
- TyAlias ( Defaultness , Generics , GenericBounds , Option < P < Ty > > ) ,
2868
+ /// An foreign function.
2869
+ Fn ( Box < FnKind > ) ,
2870
+ /// An foreign type.
2871
+ TyAlias ( Box < TyAliasKind > ) ,
2853
2872
/// A macro expanding to foreign items.
2854
2873
MacCall ( MacCall ) ,
2855
2874
}
@@ -2858,8 +2877,8 @@ impl From<ForeignItemKind> for ItemKind {
2858
2877
fn from ( foreign_item_kind : ForeignItemKind ) -> ItemKind {
2859
2878
match foreign_item_kind {
2860
2879
ForeignItemKind :: Static ( a, b, c) => ItemKind :: Static ( a, b, c) ,
2861
- ForeignItemKind :: Fn ( a , b , c , d ) => ItemKind :: Fn ( a , b , c , d ) ,
2862
- ForeignItemKind :: TyAlias ( a , b , c , d ) => ItemKind :: TyAlias ( a , b , c , d ) ,
2880
+ ForeignItemKind :: Fn ( fn_kind ) => ItemKind :: Fn ( fn_kind ) ,
2881
+ ForeignItemKind :: TyAlias ( ty_alias_kind ) => ItemKind :: TyAlias ( ty_alias_kind ) ,
2863
2882
ForeignItemKind :: MacCall ( a) => ItemKind :: MacCall ( a) ,
2864
2883
}
2865
2884
}
@@ -2871,8 +2890,8 @@ impl TryFrom<ItemKind> for ForeignItemKind {
2871
2890
fn try_from ( item_kind : ItemKind ) -> Result < ForeignItemKind , ItemKind > {
2872
2891
Ok ( match item_kind {
2873
2892
ItemKind :: Static ( a, b, c) => ForeignItemKind :: Static ( a, b, c) ,
2874
- ItemKind :: Fn ( a , b , c , d ) => ForeignItemKind :: Fn ( a , b , c , d ) ,
2875
- ItemKind :: TyAlias ( a , b , c , d ) => ForeignItemKind :: TyAlias ( a , b , c , d ) ,
2893
+ ItemKind :: Fn ( fn_kind ) => ForeignItemKind :: Fn ( fn_kind ) ,
2894
+ ItemKind :: TyAlias ( ty_alias_kind ) => ForeignItemKind :: TyAlias ( ty_alias_kind ) ,
2876
2895
ItemKind :: MacCall ( a) => ForeignItemKind :: MacCall ( a) ,
2877
2896
_ => return Err ( item_kind) ,
2878
2897
} )
0 commit comments