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