@@ -3311,9 +3311,6 @@ pub struct Item<K = ItemKind> {
3311
3311
pub id : NodeId ,
3312
3312
pub span : Span ,
3313
3313
pub vis : Visibility ,
3314
- /// The name of the item.
3315
- /// It might be a dummy name in case of anonymous items.
3316
- pub ident : Ident ,
3317
3314
3318
3315
pub kind : K ,
3319
3316
@@ -3335,23 +3332,23 @@ impl Item {
3335
3332
3336
3333
pub fn opt_generics ( & self ) -> Option < & Generics > {
3337
3334
match & self . kind {
3338
- ItemKind :: ExternCrate ( _ )
3335
+ ItemKind :: ExternCrate ( .. )
3339
3336
| ItemKind :: Use ( _)
3340
- | ItemKind :: Mod ( _ , _ )
3337
+ | ItemKind :: Mod ( .. )
3341
3338
| ItemKind :: ForeignMod ( _)
3342
3339
| ItemKind :: GlobalAsm ( _)
3343
3340
| ItemKind :: MacCall ( _)
3344
3341
| ItemKind :: Delegation ( _)
3345
3342
| ItemKind :: DelegationMac ( _)
3346
- | ItemKind :: MacroDef ( _ ) => None ,
3343
+ | ItemKind :: MacroDef ( .. ) => None ,
3347
3344
ItemKind :: Static ( _) => None ,
3348
3345
ItemKind :: Const ( i) => Some ( & i. generics ) ,
3349
3346
ItemKind :: Fn ( i) => Some ( & i. generics ) ,
3350
3347
ItemKind :: TyAlias ( i) => Some ( & i. generics ) ,
3351
- ItemKind :: TraitAlias ( generics, _)
3352
- | ItemKind :: Enum ( _, generics)
3353
- | ItemKind :: Struct ( _, generics)
3354
- | ItemKind :: Union ( _, generics) => Some ( & generics) ,
3348
+ ItemKind :: TraitAlias ( _ , generics, _)
3349
+ | ItemKind :: Enum ( _, _ , generics)
3350
+ | ItemKind :: Struct ( _, _ , generics)
3351
+ | ItemKind :: Union ( _, _ , generics) => Some ( & generics) ,
3355
3352
ItemKind :: Trait ( i) => Some ( & i. generics ) ,
3356
3353
ItemKind :: Impl ( i) => Some ( & i. generics ) ,
3357
3354
}
@@ -3428,6 +3425,7 @@ impl Default for FnHeader {
3428
3425
pub struct Trait {
3429
3426
pub safety : Safety ,
3430
3427
pub is_auto : IsAuto ,
3428
+ pub ident : Ident ,
3431
3429
pub generics : Generics ,
3432
3430
pub bounds : GenericBounds ,
3433
3431
pub items : ThinVec < P < AssocItem > > ,
@@ -3473,6 +3471,7 @@ pub struct TyAliasWhereClauses {
3473
3471
#[ derive( Clone , Encodable , Decodable , Debug ) ]
3474
3472
pub struct TyAlias {
3475
3473
pub defaultness : Defaultness ,
3474
+ pub ident : Ident ,
3476
3475
pub generics : Generics ,
3477
3476
pub where_clauses : TyAliasWhereClauses ,
3478
3477
pub bounds : GenericBounds ,
@@ -3501,6 +3500,7 @@ pub struct FnContract {
3501
3500
#[ derive( Clone , Encodable , Decodable , Debug ) ]
3502
3501
pub struct Fn {
3503
3502
pub defaultness : Defaultness ,
3503
+ pub ident : Ident ,
3504
3504
pub generics : Generics ,
3505
3505
pub sig : FnSig ,
3506
3506
pub contract : Option < P < FnContract > > ,
@@ -3514,6 +3514,7 @@ pub struct Delegation {
3514
3514
pub id : NodeId ,
3515
3515
pub qself : Option < P < QSelf > > ,
3516
3516
pub path : Path ,
3517
+ pub ident : Ident ,
3517
3518
pub rename : Option < Ident > ,
3518
3519
pub body : Option < P < Block > > ,
3519
3520
/// The item was expanded from a glob delegation item.
@@ -3531,6 +3532,7 @@ pub struct DelegationMac {
3531
3532
3532
3533
#[ derive( Clone , Encodable , Decodable , Debug ) ]
3533
3534
pub struct StaticItem {
3535
+ pub ident : Ident ,
3534
3536
pub ty : P < Ty > ,
3535
3537
pub safety : Safety ,
3536
3538
pub mutability : Mutability ,
@@ -3540,6 +3542,7 @@ pub struct StaticItem {
3540
3542
#[ derive( Clone , Encodable , Decodable , Debug ) ]
3541
3543
pub struct ConstItem {
3542
3544
pub defaultness : Defaultness ,
3545
+ pub ident : Ident ,
3543
3546
pub generics : Generics ,
3544
3547
pub ty : P < Ty > ,
3545
3548
pub expr : Option < P < Expr > > ,
@@ -3551,7 +3554,7 @@ pub enum ItemKind {
3551
3554
/// An `extern crate` item, with the optional *original* crate name if the crate was renamed.
3552
3555
///
3553
3556
/// E.g., `extern crate foo` or `extern crate foo_bar as foo`.
3554
- ExternCrate ( Option < Symbol > ) ,
3557
+ ExternCrate ( Option < Symbol > , Ident ) ,
3555
3558
/// A use declaration item (`use`).
3556
3559
///
3557
3560
/// E.g., `use foo;`, `use foo::bar;` or `use foo::bar as FooBar;`.
@@ -3573,7 +3576,7 @@ pub enum ItemKind {
3573
3576
/// E.g., `mod foo;` or `mod foo { .. }`.
3574
3577
/// `unsafe` keyword on modules is accepted syntactically for macro DSLs, but not
3575
3578
/// semantically by Rust.
3576
- Mod ( Safety , ModKind ) ,
3579
+ Mod ( Safety , Ident , ModKind ) ,
3577
3580
/// An external module (`extern`).
3578
3581
///
3579
3582
/// E.g., `extern {}` or `extern "C" {}`.
@@ -3587,23 +3590,23 @@ pub enum ItemKind {
3587
3590
/// An enum definition (`enum`).
3588
3591
///
3589
3592
/// E.g., `enum Foo<A, B> { C<A>, D<B> }`.
3590
- Enum ( EnumDef , Generics ) ,
3593
+ Enum ( Ident , EnumDef , Generics ) ,
3591
3594
/// A struct definition (`struct`).
3592
3595
///
3593
3596
/// E.g., `struct Foo<A> { x: A }`.
3594
- Struct ( VariantData , Generics ) ,
3597
+ Struct ( Ident , VariantData , Generics ) ,
3595
3598
/// A union definition (`union`).
3596
3599
///
3597
3600
/// E.g., `union Foo<A, B> { x: A, y: B }`.
3598
- Union ( VariantData , Generics ) ,
3601
+ Union ( Ident , VariantData , Generics ) ,
3599
3602
/// A trait declaration (`trait`).
3600
3603
///
3601
3604
/// E.g., `trait Foo { .. }`, `trait Foo<T> { .. }` or `auto trait Foo {}`.
3602
3605
Trait ( Box < Trait > ) ,
3603
3606
/// Trait alias.
3604
3607
///
3605
3608
/// E.g., `trait Foo = Bar + Quux;`.
3606
- TraitAlias ( Generics , GenericBounds ) ,
3609
+ TraitAlias ( Ident , Generics , GenericBounds ) ,
3607
3610
/// An implementation.
3608
3611
///
3609
3612
/// E.g., `impl<A> Foo<A> { .. }` or `impl<A> Trait for Foo<A> { .. }`.
@@ -3614,7 +3617,7 @@ pub enum ItemKind {
3614
3617
MacCall ( P < MacCall > ) ,
3615
3618
3616
3619
/// A macro definition.
3617
- MacroDef ( MacroDef ) ,
3620
+ MacroDef ( Ident , MacroDef ) ,
3618
3621
3619
3622
/// A single delegation item (`reuse`).
3620
3623
///
@@ -3626,6 +3629,31 @@ pub enum ItemKind {
3626
3629
}
3627
3630
3628
3631
impl ItemKind {
3632
+ pub fn ident ( & self ) -> Option < Ident > {
3633
+ match * self {
3634
+ ItemKind :: ExternCrate ( _, ident)
3635
+ | ItemKind :: Static ( box StaticItem { ident, .. } )
3636
+ | ItemKind :: Const ( box ConstItem { ident, .. } )
3637
+ | ItemKind :: Fn ( box Fn { ident, .. } )
3638
+ | ItemKind :: Mod ( _, ident, _)
3639
+ | ItemKind :: TyAlias ( box TyAlias { ident, .. } )
3640
+ | ItemKind :: Enum ( ident, ..)
3641
+ | ItemKind :: Struct ( ident, ..)
3642
+ | ItemKind :: Union ( ident, ..)
3643
+ | ItemKind :: Trait ( box Trait { ident, .. } )
3644
+ | ItemKind :: TraitAlias ( ident, ..)
3645
+ | ItemKind :: MacroDef ( ident, _)
3646
+ | ItemKind :: Delegation ( box Delegation { ident, .. } ) => Some ( ident) ,
3647
+
3648
+ ItemKind :: Use ( _)
3649
+ | ItemKind :: ForeignMod ( _)
3650
+ | ItemKind :: GlobalAsm ( _)
3651
+ | ItemKind :: Impl ( _)
3652
+ | ItemKind :: MacCall ( _)
3653
+ | ItemKind :: DelegationMac ( _) => None ,
3654
+ }
3655
+ }
3656
+
3629
3657
/// "a" or "an"
3630
3658
pub fn article ( & self ) -> & ' static str {
3631
3659
use ItemKind :: * ;
@@ -3666,11 +3694,11 @@ impl ItemKind {
3666
3694
Self :: Fn ( box Fn { generics, .. } )
3667
3695
| Self :: TyAlias ( box TyAlias { generics, .. } )
3668
3696
| Self :: Const ( box ConstItem { generics, .. } )
3669
- | Self :: Enum ( _, generics)
3670
- | Self :: Struct ( _, generics)
3671
- | Self :: Union ( _, generics)
3697
+ | Self :: Enum ( _, _ , generics)
3698
+ | Self :: Struct ( _, _ , generics)
3699
+ | Self :: Union ( _, _ , generics)
3672
3700
| Self :: Trait ( box Trait { generics, .. } )
3673
- | Self :: TraitAlias ( generics, _)
3701
+ | Self :: TraitAlias ( _ , generics, _)
3674
3702
| Self :: Impl ( box Impl { generics, .. } ) => Some ( generics) ,
3675
3703
_ => None ,
3676
3704
}
@@ -3706,6 +3734,17 @@ pub enum AssocItemKind {
3706
3734
}
3707
3735
3708
3736
impl AssocItemKind {
3737
+ pub fn ident ( & self ) -> Option < Ident > {
3738
+ match * self {
3739
+ AssocItemKind :: Const ( box ConstItem { ident, .. } )
3740
+ | AssocItemKind :: Fn ( box Fn { ident, .. } )
3741
+ | AssocItemKind :: Type ( box TyAlias { ident, .. } )
3742
+ | AssocItemKind :: Delegation ( box Delegation { ident, .. } ) => Some ( ident) ,
3743
+
3744
+ AssocItemKind :: MacCall ( _) | AssocItemKind :: DelegationMac ( _) => None ,
3745
+ }
3746
+ }
3747
+
3709
3748
pub fn defaultness ( & self ) -> Defaultness {
3710
3749
match * self {
3711
3750
Self :: Const ( box ConstItem { defaultness, .. } )
@@ -3752,14 +3791,26 @@ impl TryFrom<ItemKind> for AssocItemKind {
3752
3791
pub enum ForeignItemKind {
3753
3792
/// A foreign static item (`static FOO: u8`).
3754
3793
Static ( Box < StaticItem > ) ,
3755
- /// An foreign function.
3794
+ /// A foreign function.
3756
3795
Fn ( Box < Fn > ) ,
3757
- /// An foreign type.
3796
+ /// A foreign type.
3758
3797
TyAlias ( Box < TyAlias > ) ,
3759
3798
/// A macro expanding to foreign items.
3760
3799
MacCall ( P < MacCall > ) ,
3761
3800
}
3762
3801
3802
+ impl ForeignItemKind {
3803
+ pub fn ident ( & self ) -> Option < Ident > {
3804
+ match * self {
3805
+ ForeignItemKind :: Static ( box StaticItem { ident, .. } )
3806
+ | ForeignItemKind :: Fn ( box Fn { ident, .. } )
3807
+ | ForeignItemKind :: TyAlias ( box TyAlias { ident, .. } ) => Some ( ident) ,
3808
+
3809
+ ForeignItemKind :: MacCall ( _) => None ,
3810
+ }
3811
+ }
3812
+ }
3813
+
3763
3814
impl From < ForeignItemKind > for ItemKind {
3764
3815
fn from ( foreign_item_kind : ForeignItemKind ) -> ItemKind {
3765
3816
match foreign_item_kind {
@@ -3796,21 +3847,21 @@ mod size_asserts {
3796
3847
3797
3848
use super :: * ;
3798
3849
// tidy-alphabetical-start
3799
- static_assert_size ! ( AssocItem , 88 ) ;
3850
+ static_assert_size ! ( AssocItem , 80 ) ;
3800
3851
static_assert_size ! ( AssocItemKind , 16 ) ;
3801
3852
static_assert_size ! ( Attribute , 32 ) ;
3802
3853
static_assert_size ! ( Block , 32 ) ;
3803
3854
static_assert_size ! ( Expr , 72 ) ;
3804
3855
static_assert_size ! ( ExprKind , 40 ) ;
3805
- static_assert_size ! ( Fn , 176 ) ;
3806
- static_assert_size ! ( ForeignItem , 88 ) ;
3856
+ static_assert_size ! ( Fn , 184 ) ;
3857
+ static_assert_size ! ( ForeignItem , 80 ) ;
3807
3858
static_assert_size ! ( ForeignItemKind , 16 ) ;
3808
3859
static_assert_size ! ( GenericArg , 24 ) ;
3809
3860
static_assert_size ! ( GenericBound , 88 ) ;
3810
3861
static_assert_size ! ( Generics , 40 ) ;
3811
3862
static_assert_size ! ( Impl , 136 ) ;
3812
- static_assert_size ! ( Item , 136 ) ;
3813
- static_assert_size ! ( ItemKind , 64 ) ;
3863
+ static_assert_size ! ( Item , 144 ) ;
3864
+ static_assert_size ! ( ItemKind , 80 ) ;
3814
3865
static_assert_size ! ( LitKind , 24 ) ;
3815
3866
static_assert_size ! ( Local , 80 ) ;
3816
3867
static_assert_size ! ( MetaItemLit , 40 ) ;
0 commit comments