@@ -319,10 +319,7 @@ pub(crate) struct Item {
319
319
/// The name of this item.
320
320
/// Optional because not every item has a name, e.g. impls.
321
321
pub ( crate ) name : Option < Symbol > ,
322
- pub ( crate ) attrs : Box < Attributes > ,
323
- /// Information about this item that is specific to what kind of item it is.
324
- /// E.g., struct vs enum vs function.
325
- pub ( crate ) kind : Box < ItemKind > ,
322
+ pub ( crate ) inner : Box < ItemInner > ,
326
323
pub ( crate ) item_id : ItemId ,
327
324
/// This is the `LocalDefId` of the `use` statement if the item was inlined.
328
325
/// The crate metadata doesn't hold this information, so the `use` statement
@@ -331,6 +328,21 @@ pub(crate) struct Item {
331
328
pub ( crate ) cfg : Option < Arc < Cfg > > ,
332
329
}
333
330
331
+ #[ derive( Clone ) ]
332
+ pub ( crate ) struct ItemInner {
333
+ /// Information about this item that is specific to what kind of item it is.
334
+ /// E.g., struct vs enum vs function.
335
+ pub ( crate ) kind : ItemKind ,
336
+ pub ( crate ) attrs : Attributes ,
337
+ }
338
+
339
+ impl std:: ops:: Deref for Item {
340
+ type Target = ItemInner ;
341
+ fn deref ( & self ) -> & ItemInner {
342
+ & * self . inner
343
+ }
344
+ }
345
+
334
346
/// NOTE: this does NOT unconditionally print every item, to avoid thousands of lines of logs.
335
347
/// If you want to see the debug output for attributes and the `kind` as well, use `{:#?}` instead of `{:?}`.
336
348
impl fmt:: Debug for Item {
@@ -390,9 +402,9 @@ impl Item {
390
402
}
391
403
392
404
pub ( crate ) fn span ( & self , tcx : TyCtxt < ' _ > ) -> Option < Span > {
393
- let kind = match & * self . kind {
394
- ItemKind :: StrippedItem ( k) => k,
395
- _ => & * self . kind ,
405
+ let kind = match & self . kind {
406
+ ItemKind :: StrippedItem ( k) => & * k,
407
+ _ => & self . kind ,
396
408
} ;
397
409
match kind {
398
410
ItemKind :: ModuleItem ( Module { span, .. } ) => Some ( * span) ,
@@ -437,7 +449,7 @@ impl Item {
437
449
def_id,
438
450
name,
439
451
kind,
440
- Box :: new ( Attributes :: from_ast ( ast_attrs) ) ,
452
+ Attributes :: from_ast ( ast_attrs) ,
441
453
ast_attrs. cfg ( cx. tcx , & cx. cache . hidden_cfg ) ,
442
454
)
443
455
}
@@ -446,16 +458,15 @@ impl Item {
446
458
def_id : DefId ,
447
459
name : Option < Symbol > ,
448
460
kind : ItemKind ,
449
- attrs : Box < Attributes > ,
461
+ attrs : Attributes ,
450
462
cfg : Option < Arc < Cfg > > ,
451
463
) -> Item {
452
464
trace ! ( "name={name:?}, def_id={def_id:?} cfg={cfg:?}" ) ;
453
465
454
466
Item {
455
467
item_id : def_id. into ( ) ,
456
- kind : Box :: new ( kind) ,
468
+ inner : Box :: new ( ItemInner { kind, attrs } ) ,
457
469
name,
458
- attrs,
459
470
cfg,
460
471
inline_stmt_id : None ,
461
472
}
@@ -526,16 +537,16 @@ impl Item {
526
537
self . type_ ( ) == ItemType :: Variant
527
538
}
528
539
pub ( crate ) fn is_associated_type ( & self ) -> bool {
529
- matches ! ( & * self . kind, AssocTypeItem ( ..) | StrippedItem ( box AssocTypeItem ( ..) ) )
540
+ matches ! ( self . kind, AssocTypeItem ( ..) | StrippedItem ( box AssocTypeItem ( ..) ) )
530
541
}
531
542
pub ( crate ) fn is_ty_associated_type ( & self ) -> bool {
532
- matches ! ( & * self . kind, TyAssocTypeItem ( ..) | StrippedItem ( box TyAssocTypeItem ( ..) ) )
543
+ matches ! ( self . kind, TyAssocTypeItem ( ..) | StrippedItem ( box TyAssocTypeItem ( ..) ) )
533
544
}
534
545
pub ( crate ) fn is_associated_const ( & self ) -> bool {
535
- matches ! ( & * self . kind, AssocConstItem ( ..) | StrippedItem ( box AssocConstItem ( ..) ) )
546
+ matches ! ( self . kind, AssocConstItem ( ..) | StrippedItem ( box AssocConstItem ( ..) ) )
536
547
}
537
548
pub ( crate ) fn is_ty_associated_const ( & self ) -> bool {
538
- matches ! ( & * self . kind, TyAssocConstItem ( ..) | StrippedItem ( box TyAssocConstItem ( ..) ) )
549
+ matches ! ( self . kind, TyAssocConstItem ( ..) | StrippedItem ( box TyAssocConstItem ( ..) ) )
539
550
}
540
551
pub ( crate ) fn is_method ( & self ) -> bool {
541
552
self . type_ ( ) == ItemType :: Method
@@ -562,14 +573,14 @@ impl Item {
562
573
self . type_ ( ) == ItemType :: Keyword
563
574
}
564
575
pub ( crate ) fn is_stripped ( & self ) -> bool {
565
- match * self . kind {
576
+ match self . kind {
566
577
StrippedItem ( ..) => true ,
567
578
ImportItem ( ref i) => !i. should_be_displayed ,
568
579
_ => false ,
569
580
}
570
581
}
571
582
pub ( crate ) fn has_stripped_entries ( & self ) -> Option < bool > {
572
- match * self . kind {
583
+ match self . kind {
573
584
StructItem ( ref struct_) => Some ( struct_. has_stripped_entries ( ) ) ,
574
585
UnionItem ( ref union_) => Some ( union_. has_stripped_entries ( ) ) ,
575
586
EnumItem ( ref enum_) => Some ( enum_. has_stripped_entries ( ) ) ,
@@ -612,7 +623,7 @@ impl Item {
612
623
}
613
624
614
625
pub ( crate ) fn is_default ( & self ) -> bool {
615
- match * self . kind {
626
+ match self . kind {
616
627
ItemKind :: MethodItem ( _, Some ( defaultness) ) => {
617
628
defaultness. has_value ( ) && !defaultness. is_final ( )
618
629
}
@@ -640,7 +651,7 @@ impl Item {
640
651
} ;
641
652
hir:: FnHeader { safety : sig. safety ( ) , abi : sig. abi ( ) , constness, asyncness }
642
653
}
643
- let header = match * self . kind {
654
+ let header = match self . kind {
644
655
ItemKind :: ForeignFunctionItem ( _, safety) => {
645
656
let def_id = self . def_id ( ) . unwrap ( ) ;
646
657
let abi = tcx. fn_sig ( def_id) . skip_binder ( ) . abi ( ) ;
@@ -679,7 +690,7 @@ impl Item {
679
690
ItemId :: DefId ( def_id) => def_id,
680
691
} ;
681
692
682
- match * self . kind {
693
+ match self . kind {
683
694
// Primitives and Keywords are written in the source code as private modules.
684
695
// The modules need to be private so that nobody actually uses them, but the
685
696
// keywords and primitives that they are documenting are public.
@@ -2566,13 +2577,13 @@ mod size_asserts {
2566
2577
2567
2578
use super :: * ;
2568
2579
// tidy-alphabetical-start
2569
- static_assert_size ! ( Crate , 64 ) ; // frequently moved by-value
2580
+ static_assert_size ! ( Crate , 56 ) ; // frequently moved by-value
2570
2581
static_assert_size ! ( DocFragment , 32 ) ;
2571
2582
static_assert_size ! ( GenericArg , 32 ) ;
2572
2583
static_assert_size ! ( GenericArgs , 32 ) ;
2573
2584
static_assert_size ! ( GenericParamDef , 40 ) ;
2574
2585
static_assert_size ! ( Generics , 16 ) ;
2575
- static_assert_size ! ( Item , 56 ) ;
2586
+ static_assert_size ! ( Item , 48 ) ;
2576
2587
static_assert_size ! ( ItemKind , 48 ) ;
2577
2588
static_assert_size ! ( PathSegment , 40 ) ;
2578
2589
static_assert_size ! ( Type , 32 ) ;
0 commit comments