@@ -3273,9 +3273,6 @@ pub struct Item<K = ItemKind> {
3273
3273
pub id : NodeId ,
3274
3274
pub span : Span ,
3275
3275
pub vis : Visibility ,
3276
- /// The name of the item.
3277
- /// It might be a dummy name in case of anonymous items.
3278
- pub ident : Ident ,
3279
3276
3280
3277
pub kind : K ,
3281
3278
@@ -3297,23 +3294,23 @@ impl Item {
3297
3294
3298
3295
pub fn opt_generics ( & self ) -> Option < & Generics > {
3299
3296
match & self . kind {
3300
- ItemKind :: ExternCrate ( _ )
3297
+ ItemKind :: ExternCrate ( .. )
3301
3298
| ItemKind :: Use ( _)
3302
- | ItemKind :: Mod ( _ , _ )
3299
+ | ItemKind :: Mod ( .. )
3303
3300
| ItemKind :: ForeignMod ( _)
3304
3301
| ItemKind :: GlobalAsm ( _)
3305
3302
| ItemKind :: MacCall ( _)
3306
3303
| ItemKind :: Delegation ( _)
3307
3304
| ItemKind :: DelegationMac ( _)
3308
- | ItemKind :: MacroDef ( _ ) => None ,
3305
+ | ItemKind :: MacroDef ( .. ) => None ,
3309
3306
ItemKind :: Static ( _) => None ,
3310
3307
ItemKind :: Const ( i) => Some ( & i. generics ) ,
3311
3308
ItemKind :: Fn ( i) => Some ( & i. generics ) ,
3312
3309
ItemKind :: TyAlias ( i) => Some ( & i. generics ) ,
3313
- ItemKind :: TraitAlias ( generics, _)
3314
- | ItemKind :: Enum ( _, generics)
3315
- | ItemKind :: Struct ( _, generics)
3316
- | ItemKind :: Union ( _, generics) => Some ( & generics) ,
3310
+ ItemKind :: TraitAlias ( _ , generics, _)
3311
+ | ItemKind :: Enum ( _, _ , generics)
3312
+ | ItemKind :: Struct ( _, _ , generics)
3313
+ | ItemKind :: Union ( _, _ , generics) => Some ( & generics) ,
3317
3314
ItemKind :: Trait ( i) => Some ( & i. generics ) ,
3318
3315
ItemKind :: Impl ( i) => Some ( & i. generics ) ,
3319
3316
}
@@ -3390,6 +3387,7 @@ impl Default for FnHeader {
3390
3387
pub struct Trait {
3391
3388
pub safety : Safety ,
3392
3389
pub is_auto : IsAuto ,
3390
+ pub ident : Ident ,
3393
3391
pub generics : Generics ,
3394
3392
pub bounds : GenericBounds ,
3395
3393
pub items : ThinVec < P < AssocItem > > ,
@@ -3435,6 +3433,7 @@ pub struct TyAliasWhereClauses {
3435
3433
#[ derive( Clone , Encodable , Decodable , Debug ) ]
3436
3434
pub struct TyAlias {
3437
3435
pub defaultness : Defaultness ,
3436
+ pub ident : Ident ,
3438
3437
pub generics : Generics ,
3439
3438
pub where_clauses : TyAliasWhereClauses ,
3440
3439
pub bounds : GenericBounds ,
@@ -3463,6 +3462,7 @@ pub struct FnContract {
3463
3462
#[ derive( Clone , Encodable , Decodable , Debug ) ]
3464
3463
pub struct Fn {
3465
3464
pub defaultness : Defaultness ,
3465
+ pub ident : Ident ,
3466
3466
pub generics : Generics ,
3467
3467
pub sig : FnSig ,
3468
3468
pub contract : Option < P < FnContract > > ,
@@ -3476,6 +3476,7 @@ pub struct Delegation {
3476
3476
pub id : NodeId ,
3477
3477
pub qself : Option < P < QSelf > > ,
3478
3478
pub path : Path ,
3479
+ pub ident : Ident ,
3479
3480
pub rename : Option < Ident > ,
3480
3481
pub body : Option < P < Block > > ,
3481
3482
/// The item was expanded from a glob delegation item.
@@ -3493,6 +3494,7 @@ pub struct DelegationMac {
3493
3494
3494
3495
#[ derive( Clone , Encodable , Decodable , Debug ) ]
3495
3496
pub struct StaticItem {
3497
+ pub ident : Ident ,
3496
3498
pub ty : P < Ty > ,
3497
3499
pub safety : Safety ,
3498
3500
pub mutability : Mutability ,
@@ -3502,6 +3504,7 @@ pub struct StaticItem {
3502
3504
#[ derive( Clone , Encodable , Decodable , Debug ) ]
3503
3505
pub struct ConstItem {
3504
3506
pub defaultness : Defaultness ,
3507
+ pub ident : Ident ,
3505
3508
pub generics : Generics ,
3506
3509
pub ty : P < Ty > ,
3507
3510
pub expr : Option < P < Expr > > ,
@@ -3513,7 +3516,7 @@ pub enum ItemKind {
3513
3516
/// An `extern crate` item, with the optional *original* crate name if the crate was renamed.
3514
3517
///
3515
3518
/// E.g., `extern crate foo` or `extern crate foo_bar as foo`.
3516
- ExternCrate ( Option < Symbol > ) ,
3519
+ ExternCrate ( Option < Symbol > , Ident ) ,
3517
3520
/// A use declaration item (`use`).
3518
3521
///
3519
3522
/// E.g., `use foo;`, `use foo::bar;` or `use foo::bar as FooBar;`.
@@ -3535,7 +3538,7 @@ pub enum ItemKind {
3535
3538
/// E.g., `mod foo;` or `mod foo { .. }`.
3536
3539
/// `unsafe` keyword on modules is accepted syntactically for macro DSLs, but not
3537
3540
/// semantically by Rust.
3538
- Mod ( Safety , ModKind ) ,
3541
+ Mod ( Safety , Ident , ModKind ) ,
3539
3542
/// An external module (`extern`).
3540
3543
///
3541
3544
/// E.g., `extern {}` or `extern "C" {}`.
@@ -3549,23 +3552,23 @@ pub enum ItemKind {
3549
3552
/// An enum definition (`enum`).
3550
3553
///
3551
3554
/// E.g., `enum Foo<A, B> { C<A>, D<B> }`.
3552
- Enum ( EnumDef , Generics ) ,
3555
+ Enum ( Ident , EnumDef , Generics ) ,
3553
3556
/// A struct definition (`struct`).
3554
3557
///
3555
3558
/// E.g., `struct Foo<A> { x: A }`.
3556
- Struct ( VariantData , Generics ) ,
3559
+ Struct ( Ident , VariantData , Generics ) ,
3557
3560
/// A union definition (`union`).
3558
3561
///
3559
3562
/// E.g., `union Foo<A, B> { x: A, y: B }`.
3560
- Union ( VariantData , Generics ) ,
3563
+ Union ( Ident , VariantData , Generics ) ,
3561
3564
/// A trait declaration (`trait`).
3562
3565
///
3563
3566
/// E.g., `trait Foo { .. }`, `trait Foo<T> { .. }` or `auto trait Foo {}`.
3564
3567
Trait ( Box < Trait > ) ,
3565
3568
/// Trait alias.
3566
3569
///
3567
3570
/// E.g., `trait Foo = Bar + Quux;`.
3568
- TraitAlias ( Generics , GenericBounds ) ,
3571
+ TraitAlias ( Ident , Generics , GenericBounds ) ,
3569
3572
/// An implementation.
3570
3573
///
3571
3574
/// E.g., `impl<A> Foo<A> { .. }` or `impl<A> Trait for Foo<A> { .. }`.
@@ -3576,7 +3579,7 @@ pub enum ItemKind {
3576
3579
MacCall ( P < MacCall > ) ,
3577
3580
3578
3581
/// A macro definition.
3579
- MacroDef ( MacroDef ) ,
3582
+ MacroDef ( Ident , MacroDef ) ,
3580
3583
3581
3584
/// A single delegation item (`reuse`).
3582
3585
///
@@ -3588,6 +3591,31 @@ pub enum ItemKind {
3588
3591
}
3589
3592
3590
3593
impl ItemKind {
3594
+ pub fn ident ( & self ) -> Option < Ident > {
3595
+ match * self {
3596
+ ItemKind :: ExternCrate ( _, ident)
3597
+ | ItemKind :: Static ( box StaticItem { ident, .. } )
3598
+ | ItemKind :: Const ( box ConstItem { ident, .. } )
3599
+ | ItemKind :: Fn ( box Fn { ident, .. } )
3600
+ | ItemKind :: Mod ( _, ident, _)
3601
+ | ItemKind :: TyAlias ( box TyAlias { ident, .. } )
3602
+ | ItemKind :: Enum ( ident, ..)
3603
+ | ItemKind :: Struct ( ident, ..)
3604
+ | ItemKind :: Union ( ident, ..)
3605
+ | ItemKind :: Trait ( box Trait { ident, .. } )
3606
+ | ItemKind :: TraitAlias ( ident, ..)
3607
+ | ItemKind :: MacroDef ( ident, _)
3608
+ | ItemKind :: Delegation ( box Delegation { ident, .. } ) => Some ( ident) ,
3609
+
3610
+ ItemKind :: Use ( _)
3611
+ | ItemKind :: ForeignMod ( _)
3612
+ | ItemKind :: GlobalAsm ( _)
3613
+ | ItemKind :: Impl ( _)
3614
+ | ItemKind :: MacCall ( _)
3615
+ | ItemKind :: DelegationMac ( _) => None ,
3616
+ }
3617
+ }
3618
+
3591
3619
/// "a" or "an"
3592
3620
pub fn article ( & self ) -> & ' static str {
3593
3621
use ItemKind :: * ;
@@ -3628,11 +3656,11 @@ impl ItemKind {
3628
3656
Self :: Fn ( box Fn { generics, .. } )
3629
3657
| Self :: TyAlias ( box TyAlias { generics, .. } )
3630
3658
| Self :: Const ( box ConstItem { generics, .. } )
3631
- | Self :: Enum ( _, generics)
3632
- | Self :: Struct ( _, generics)
3633
- | Self :: Union ( _, generics)
3659
+ | Self :: Enum ( _, _ , generics)
3660
+ | Self :: Struct ( _, _ , generics)
3661
+ | Self :: Union ( _, _ , generics)
3634
3662
| Self :: Trait ( box Trait { generics, .. } )
3635
- | Self :: TraitAlias ( generics, _)
3663
+ | Self :: TraitAlias ( _ , generics, _)
3636
3664
| Self :: Impl ( box Impl { generics, .. } ) => Some ( generics) ,
3637
3665
_ => None ,
3638
3666
}
@@ -3668,6 +3696,17 @@ pub enum AssocItemKind {
3668
3696
}
3669
3697
3670
3698
impl AssocItemKind {
3699
+ pub fn ident ( & self ) -> Option < Ident > {
3700
+ match * self {
3701
+ AssocItemKind :: Const ( box ConstItem { ident, .. } )
3702
+ | AssocItemKind :: Fn ( box Fn { ident, .. } )
3703
+ | AssocItemKind :: Type ( box TyAlias { ident, .. } )
3704
+ | AssocItemKind :: Delegation ( box Delegation { ident, .. } ) => Some ( ident) ,
3705
+
3706
+ AssocItemKind :: MacCall ( _) | AssocItemKind :: DelegationMac ( _) => None ,
3707
+ }
3708
+ }
3709
+
3671
3710
pub fn defaultness ( & self ) -> Defaultness {
3672
3711
match * self {
3673
3712
Self :: Const ( box ConstItem { defaultness, .. } )
@@ -3714,14 +3753,26 @@ impl TryFrom<ItemKind> for AssocItemKind {
3714
3753
pub enum ForeignItemKind {
3715
3754
/// A foreign static item (`static FOO: u8`).
3716
3755
Static ( Box < StaticItem > ) ,
3717
- /// An foreign function.
3756
+ /// A foreign function.
3718
3757
Fn ( Box < Fn > ) ,
3719
- /// An foreign type.
3758
+ /// A foreign type.
3720
3759
TyAlias ( Box < TyAlias > ) ,
3721
3760
/// A macro expanding to foreign items.
3722
3761
MacCall ( P < MacCall > ) ,
3723
3762
}
3724
3763
3764
+ impl ForeignItemKind {
3765
+ pub fn ident ( & self ) -> Option < Ident > {
3766
+ match * self {
3767
+ ForeignItemKind :: Static ( box StaticItem { ident, .. } )
3768
+ | ForeignItemKind :: Fn ( box Fn { ident, .. } )
3769
+ | ForeignItemKind :: TyAlias ( box TyAlias { ident, .. } ) => Some ( ident) ,
3770
+
3771
+ ForeignItemKind :: MacCall ( _) => None ,
3772
+ }
3773
+ }
3774
+ }
3775
+
3725
3776
impl From < ForeignItemKind > for ItemKind {
3726
3777
fn from ( foreign_item_kind : ForeignItemKind ) -> ItemKind {
3727
3778
match foreign_item_kind {
@@ -3758,21 +3809,21 @@ mod size_asserts {
3758
3809
3759
3810
use super :: * ;
3760
3811
// tidy-alphabetical-start
3761
- static_assert_size ! ( AssocItem , 88 ) ;
3812
+ static_assert_size ! ( AssocItem , 80 ) ;
3762
3813
static_assert_size ! ( AssocItemKind , 16 ) ;
3763
3814
static_assert_size ! ( Attribute , 32 ) ;
3764
3815
static_assert_size ! ( Block , 32 ) ;
3765
3816
static_assert_size ! ( Expr , 72 ) ;
3766
3817
static_assert_size ! ( ExprKind , 40 ) ;
3767
- static_assert_size ! ( Fn , 176 ) ;
3768
- static_assert_size ! ( ForeignItem , 88 ) ;
3818
+ static_assert_size ! ( Fn , 184 ) ;
3819
+ static_assert_size ! ( ForeignItem , 80 ) ;
3769
3820
static_assert_size ! ( ForeignItemKind , 16 ) ;
3770
3821
static_assert_size ! ( GenericArg , 24 ) ;
3771
3822
static_assert_size ! ( GenericBound , 88 ) ;
3772
3823
static_assert_size ! ( Generics , 40 ) ;
3773
3824
static_assert_size ! ( Impl , 136 ) ;
3774
- static_assert_size ! ( Item , 136 ) ;
3775
- static_assert_size ! ( ItemKind , 64 ) ;
3825
+ static_assert_size ! ( Item , 144 ) ;
3826
+ static_assert_size ! ( ItemKind , 80 ) ;
3776
3827
static_assert_size ! ( LitKind , 24 ) ;
3777
3828
static_assert_size ! ( Local , 80 ) ;
3778
3829
static_assert_size ! ( MetaItemLit , 40 ) ;
0 commit comments