@@ -3303,9 +3303,6 @@ pub struct Item<K = ItemKind> {
3303
3303
pub id : NodeId ,
3304
3304
pub span : Span ,
3305
3305
pub vis : Visibility ,
3306
- /// The name of the item.
3307
- /// It might be a dummy name in case of anonymous items.
3308
- pub ident : Ident ,
3309
3306
3310
3307
pub kind : K ,
3311
3308
@@ -3327,23 +3324,23 @@ impl Item {
3327
3324
3328
3325
pub fn opt_generics ( & self ) -> Option < & Generics > {
3329
3326
match & self . kind {
3330
- ItemKind :: ExternCrate ( _ )
3327
+ ItemKind :: ExternCrate ( .. )
3331
3328
| ItemKind :: Use ( _)
3332
- | ItemKind :: Mod ( _ , _ )
3329
+ | ItemKind :: Mod ( .. )
3333
3330
| ItemKind :: ForeignMod ( _)
3334
3331
| ItemKind :: GlobalAsm ( _)
3335
3332
| ItemKind :: MacCall ( _)
3336
3333
| ItemKind :: Delegation ( _)
3337
3334
| ItemKind :: DelegationMac ( _)
3338
- | ItemKind :: MacroDef ( _ ) => None ,
3335
+ | ItemKind :: MacroDef ( .. ) => None ,
3339
3336
ItemKind :: Static ( _) => None ,
3340
3337
ItemKind :: Const ( i) => Some ( & i. generics ) ,
3341
3338
ItemKind :: Fn ( i) => Some ( & i. generics ) ,
3342
3339
ItemKind :: TyAlias ( i) => Some ( & i. generics ) ,
3343
- ItemKind :: TraitAlias ( generics, _)
3344
- | ItemKind :: Enum ( _, generics)
3345
- | ItemKind :: Struct ( _, generics)
3346
- | ItemKind :: Union ( _, generics) => Some ( & generics) ,
3340
+ ItemKind :: TraitAlias ( _ , generics, _)
3341
+ | ItemKind :: Enum ( _, _ , generics)
3342
+ | ItemKind :: Struct ( _, _ , generics)
3343
+ | ItemKind :: Union ( _, _ , generics) => Some ( & generics) ,
3347
3344
ItemKind :: Trait ( i) => Some ( & i. generics ) ,
3348
3345
ItemKind :: Impl ( i) => Some ( & i. generics ) ,
3349
3346
}
@@ -3420,6 +3417,7 @@ impl Default for FnHeader {
3420
3417
pub struct Trait {
3421
3418
pub safety : Safety ,
3422
3419
pub is_auto : IsAuto ,
3420
+ pub ident : Ident ,
3423
3421
pub generics : Generics ,
3424
3422
pub bounds : GenericBounds ,
3425
3423
pub items : ThinVec < P < AssocItem > > ,
@@ -3465,6 +3463,7 @@ pub struct TyAliasWhereClauses {
3465
3463
#[ derive( Clone , Encodable , Decodable , Debug ) ]
3466
3464
pub struct TyAlias {
3467
3465
pub defaultness : Defaultness ,
3466
+ pub ident : Ident ,
3468
3467
pub generics : Generics ,
3469
3468
pub where_clauses : TyAliasWhereClauses ,
3470
3469
pub bounds : GenericBounds ,
@@ -3493,6 +3492,7 @@ pub struct FnContract {
3493
3492
#[ derive( Clone , Encodable , Decodable , Debug ) ]
3494
3493
pub struct Fn {
3495
3494
pub defaultness : Defaultness ,
3495
+ pub ident : Ident ,
3496
3496
pub generics : Generics ,
3497
3497
pub sig : FnSig ,
3498
3498
pub contract : Option < P < FnContract > > ,
@@ -3506,6 +3506,7 @@ pub struct Delegation {
3506
3506
pub id : NodeId ,
3507
3507
pub qself : Option < P < QSelf > > ,
3508
3508
pub path : Path ,
3509
+ pub ident : Ident ,
3509
3510
pub rename : Option < Ident > ,
3510
3511
pub body : Option < P < Block > > ,
3511
3512
/// The item was expanded from a glob delegation item.
@@ -3523,6 +3524,7 @@ pub struct DelegationMac {
3523
3524
3524
3525
#[ derive( Clone , Encodable , Decodable , Debug ) ]
3525
3526
pub struct StaticItem {
3527
+ pub ident : Ident ,
3526
3528
pub ty : P < Ty > ,
3527
3529
pub safety : Safety ,
3528
3530
pub mutability : Mutability ,
@@ -3533,6 +3535,7 @@ pub struct StaticItem {
3533
3535
#[ derive( Clone , Encodable , Decodable , Debug ) ]
3534
3536
pub struct ConstItem {
3535
3537
pub defaultness : Defaultness ,
3538
+ pub ident : Ident ,
3536
3539
pub generics : Generics ,
3537
3540
pub ty : P < Ty > ,
3538
3541
pub expr : Option < P < Expr > > ,
@@ -3545,7 +3548,7 @@ pub enum ItemKind {
3545
3548
/// An `extern crate` item, with the optional *original* crate name if the crate was renamed.
3546
3549
///
3547
3550
/// E.g., `extern crate foo` or `extern crate foo_bar as foo`.
3548
- ExternCrate ( Option < Symbol > ) ,
3551
+ ExternCrate ( Option < Symbol > , Ident ) ,
3549
3552
/// A use declaration item (`use`).
3550
3553
///
3551
3554
/// E.g., `use foo;`, `use foo::bar;` or `use foo::bar as FooBar;`.
@@ -3567,7 +3570,7 @@ pub enum ItemKind {
3567
3570
/// E.g., `mod foo;` or `mod foo { .. }`.
3568
3571
/// `unsafe` keyword on modules is accepted syntactically for macro DSLs, but not
3569
3572
/// semantically by Rust.
3570
- Mod ( Safety , ModKind ) ,
3573
+ Mod ( Safety , Ident , ModKind ) ,
3571
3574
/// An external module (`extern`).
3572
3575
///
3573
3576
/// E.g., `extern {}` or `extern "C" {}`.
@@ -3581,23 +3584,23 @@ pub enum ItemKind {
3581
3584
/// An enum definition (`enum`).
3582
3585
///
3583
3586
/// E.g., `enum Foo<A, B> { C<A>, D<B> }`.
3584
- Enum ( EnumDef , Generics ) ,
3587
+ Enum ( Ident , EnumDef , Generics ) ,
3585
3588
/// A struct definition (`struct`).
3586
3589
///
3587
3590
/// E.g., `struct Foo<A> { x: A }`.
3588
- Struct ( VariantData , Generics ) ,
3591
+ Struct ( Ident , VariantData , Generics ) ,
3589
3592
/// A union definition (`union`).
3590
3593
///
3591
3594
/// E.g., `union Foo<A, B> { x: A, y: B }`.
3592
- Union ( VariantData , Generics ) ,
3595
+ Union ( Ident , VariantData , Generics ) ,
3593
3596
/// A trait declaration (`trait`).
3594
3597
///
3595
3598
/// E.g., `trait Foo { .. }`, `trait Foo<T> { .. }` or `auto trait Foo {}`.
3596
3599
Trait ( Box < Trait > ) ,
3597
3600
/// Trait alias.
3598
3601
///
3599
3602
/// E.g., `trait Foo = Bar + Quux;`.
3600
- TraitAlias ( Generics , GenericBounds ) ,
3603
+ TraitAlias ( Ident , Generics , GenericBounds ) ,
3601
3604
/// An implementation.
3602
3605
///
3603
3606
/// E.g., `impl<A> Foo<A> { .. }` or `impl<A> Trait for Foo<A> { .. }`.
@@ -3608,7 +3611,7 @@ pub enum ItemKind {
3608
3611
MacCall ( P < MacCall > ) ,
3609
3612
3610
3613
/// A macro definition.
3611
- MacroDef ( MacroDef ) ,
3614
+ MacroDef ( Ident , MacroDef ) ,
3612
3615
3613
3616
/// A single delegation item (`reuse`).
3614
3617
///
@@ -3620,6 +3623,31 @@ pub enum ItemKind {
3620
3623
}
3621
3624
3622
3625
impl ItemKind {
3626
+ pub fn ident ( & self ) -> Option < Ident > {
3627
+ match * self {
3628
+ ItemKind :: ExternCrate ( _, ident)
3629
+ | ItemKind :: Static ( box StaticItem { ident, .. } )
3630
+ | ItemKind :: Const ( box ConstItem { ident, .. } )
3631
+ | ItemKind :: Fn ( box Fn { ident, .. } )
3632
+ | ItemKind :: Mod ( _, ident, _)
3633
+ | ItemKind :: TyAlias ( box TyAlias { ident, .. } )
3634
+ | ItemKind :: Enum ( ident, ..)
3635
+ | ItemKind :: Struct ( ident, ..)
3636
+ | ItemKind :: Union ( ident, ..)
3637
+ | ItemKind :: Trait ( box Trait { ident, .. } )
3638
+ | ItemKind :: TraitAlias ( ident, ..)
3639
+ | ItemKind :: MacroDef ( ident, _)
3640
+ | ItemKind :: Delegation ( box Delegation { ident, .. } ) => Some ( ident) ,
3641
+
3642
+ ItemKind :: Use ( _)
3643
+ | ItemKind :: ForeignMod ( _)
3644
+ | ItemKind :: GlobalAsm ( _)
3645
+ | ItemKind :: Impl ( _)
3646
+ | ItemKind :: MacCall ( _)
3647
+ | ItemKind :: DelegationMac ( _) => None ,
3648
+ }
3649
+ }
3650
+
3623
3651
/// "a" or "an"
3624
3652
pub fn article ( & self ) -> & ' static str {
3625
3653
use ItemKind :: * ;
@@ -3660,11 +3688,11 @@ impl ItemKind {
3660
3688
Self :: Fn ( box Fn { generics, .. } )
3661
3689
| Self :: TyAlias ( box TyAlias { generics, .. } )
3662
3690
| Self :: Const ( box ConstItem { generics, .. } )
3663
- | Self :: Enum ( _, generics)
3664
- | Self :: Struct ( _, generics)
3665
- | Self :: Union ( _, generics)
3691
+ | Self :: Enum ( _, _ , generics)
3692
+ | Self :: Struct ( _, _ , generics)
3693
+ | Self :: Union ( _, _ , generics)
3666
3694
| Self :: Trait ( box Trait { generics, .. } )
3667
- | Self :: TraitAlias ( generics, _)
3695
+ | Self :: TraitAlias ( _ , generics, _)
3668
3696
| Self :: Impl ( box Impl { generics, .. } ) => Some ( generics) ,
3669
3697
_ => None ,
3670
3698
}
@@ -3700,6 +3728,17 @@ pub enum AssocItemKind {
3700
3728
}
3701
3729
3702
3730
impl AssocItemKind {
3731
+ pub fn ident ( & self ) -> Option < Ident > {
3732
+ match * self {
3733
+ AssocItemKind :: Const ( box ConstItem { ident, .. } )
3734
+ | AssocItemKind :: Fn ( box Fn { ident, .. } )
3735
+ | AssocItemKind :: Type ( box TyAlias { ident, .. } )
3736
+ | AssocItemKind :: Delegation ( box Delegation { ident, .. } ) => Some ( ident) ,
3737
+
3738
+ AssocItemKind :: MacCall ( _) | AssocItemKind :: DelegationMac ( _) => None ,
3739
+ }
3740
+ }
3741
+
3703
3742
pub fn defaultness ( & self ) -> Defaultness {
3704
3743
match * self {
3705
3744
Self :: Const ( box ConstItem { defaultness, .. } )
@@ -3746,14 +3785,26 @@ impl TryFrom<ItemKind> for AssocItemKind {
3746
3785
pub enum ForeignItemKind {
3747
3786
/// A foreign static item (`static FOO: u8`).
3748
3787
Static ( Box < StaticItem > ) ,
3749
- /// An foreign function.
3788
+ /// A foreign function.
3750
3789
Fn ( Box < Fn > ) ,
3751
- /// An foreign type.
3790
+ /// A foreign type.
3752
3791
TyAlias ( Box < TyAlias > ) ,
3753
3792
/// A macro expanding to foreign items.
3754
3793
MacCall ( P < MacCall > ) ,
3755
3794
}
3756
3795
3796
+ impl ForeignItemKind {
3797
+ pub fn ident ( & self ) -> Option < Ident > {
3798
+ match * self {
3799
+ ForeignItemKind :: Static ( box StaticItem { ident, .. } )
3800
+ | ForeignItemKind :: Fn ( box Fn { ident, .. } )
3801
+ | ForeignItemKind :: TyAlias ( box TyAlias { ident, .. } ) => Some ( ident) ,
3802
+
3803
+ ForeignItemKind :: MacCall ( _) => None ,
3804
+ }
3805
+ }
3806
+ }
3807
+
3757
3808
impl From < ForeignItemKind > for ItemKind {
3758
3809
fn from ( foreign_item_kind : ForeignItemKind ) -> ItemKind {
3759
3810
match foreign_item_kind {
@@ -3790,21 +3841,21 @@ mod size_asserts {
3790
3841
3791
3842
use super :: * ;
3792
3843
// tidy-alphabetical-start
3793
- static_assert_size ! ( AssocItem , 88 ) ;
3844
+ static_assert_size ! ( AssocItem , 80 ) ;
3794
3845
static_assert_size ! ( AssocItemKind , 16 ) ;
3795
3846
static_assert_size ! ( Attribute , 32 ) ;
3796
3847
static_assert_size ! ( Block , 32 ) ;
3797
3848
static_assert_size ! ( Expr , 72 ) ;
3798
3849
static_assert_size ! ( ExprKind , 40 ) ;
3799
- static_assert_size ! ( Fn , 176 ) ;
3800
- static_assert_size ! ( ForeignItem , 88 ) ;
3850
+ static_assert_size ! ( Fn , 184 ) ;
3851
+ static_assert_size ! ( ForeignItem , 80 ) ;
3801
3852
static_assert_size ! ( ForeignItemKind , 16 ) ;
3802
3853
static_assert_size ! ( GenericArg , 24 ) ;
3803
3854
static_assert_size ! ( GenericBound , 88 ) ;
3804
3855
static_assert_size ! ( Generics , 40 ) ;
3805
3856
static_assert_size ! ( Impl , 136 ) ;
3806
- static_assert_size ! ( Item , 136 ) ;
3807
- static_assert_size ! ( ItemKind , 64 ) ;
3857
+ static_assert_size ! ( Item , 144 ) ;
3858
+ static_assert_size ! ( ItemKind , 80 ) ;
3808
3859
static_assert_size ! ( LitKind , 24 ) ;
3809
3860
static_assert_size ! ( Local , 80 ) ;
3810
3861
static_assert_size ! ( MetaItemLit , 40 ) ;
0 commit comments