@@ -319,10 +319,7 @@ pub(crate) struct Item {
319319 /// The name of this item.
320320 /// Optional because not every item has a name, e.g. impls.
321321 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 > ,
326323 pub ( crate ) item_id : ItemId ,
327324 /// This is the `LocalDefId` of the `use` statement if the item was inlined.
328325 /// The crate metadata doesn't hold this information, so the `use` statement
@@ -331,6 +328,21 @@ pub(crate) struct Item {
331328 pub ( crate ) cfg : Option < Arc < Cfg > > ,
332329}
333330
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+
334346/// NOTE: this does NOT unconditionally print every item, to avoid thousands of lines of logs.
335347/// If you want to see the debug output for attributes and the `kind` as well, use `{:#?}` instead of `{:?}`.
336348impl fmt:: Debug for Item {
@@ -390,9 +402,9 @@ impl Item {
390402 }
391403
392404 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 ,
396408 } ;
397409 match kind {
398410 ItemKind :: ModuleItem ( Module { span, .. } ) => Some ( * span) ,
@@ -437,7 +449,7 @@ impl Item {
437449 def_id,
438450 name,
439451 kind,
440- Box :: new ( Attributes :: from_ast ( ast_attrs) ) ,
452+ Attributes :: from_ast ( ast_attrs) ,
441453 ast_attrs. cfg ( cx. tcx , & cx. cache . hidden_cfg ) ,
442454 )
443455 }
@@ -446,16 +458,15 @@ impl Item {
446458 def_id : DefId ,
447459 name : Option < Symbol > ,
448460 kind : ItemKind ,
449- attrs : Box < Attributes > ,
461+ attrs : Attributes ,
450462 cfg : Option < Arc < Cfg > > ,
451463 ) -> Item {
452464 trace ! ( "name={name:?}, def_id={def_id:?} cfg={cfg:?}" ) ;
453465
454466 Item {
455467 item_id : def_id. into ( ) ,
456- kind : Box :: new ( kind) ,
468+ inner : Box :: new ( ItemInner { kind, attrs } ) ,
457469 name,
458- attrs,
459470 cfg,
460471 inline_stmt_id : None ,
461472 }
@@ -526,16 +537,16 @@ impl Item {
526537 self . type_ ( ) == ItemType :: Variant
527538 }
528539 pub ( crate ) fn is_associated_type ( & self ) -> bool {
529- matches ! ( & * self . kind, AssocTypeItem ( ..) | StrippedItem ( box AssocTypeItem ( ..) ) )
540+ matches ! ( self . kind, AssocTypeItem ( ..) | StrippedItem ( box AssocTypeItem ( ..) ) )
530541 }
531542 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 ( ..) ) )
533544 }
534545 pub ( crate ) fn is_associated_const ( & self ) -> bool {
535- matches ! ( & * self . kind, AssocConstItem ( ..) | StrippedItem ( box AssocConstItem ( ..) ) )
546+ matches ! ( self . kind, AssocConstItem ( ..) | StrippedItem ( box AssocConstItem ( ..) ) )
536547 }
537548 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 ( ..) ) )
539550 }
540551 pub ( crate ) fn is_method ( & self ) -> bool {
541552 self . type_ ( ) == ItemType :: Method
@@ -562,14 +573,14 @@ impl Item {
562573 self . type_ ( ) == ItemType :: Keyword
563574 }
564575 pub ( crate ) fn is_stripped ( & self ) -> bool {
565- match * self . kind {
576+ match self . kind {
566577 StrippedItem ( ..) => true ,
567578 ImportItem ( ref i) => !i. should_be_displayed ,
568579 _ => false ,
569580 }
570581 }
571582 pub ( crate ) fn has_stripped_entries ( & self ) -> Option < bool > {
572- match * self . kind {
583+ match self . kind {
573584 StructItem ( ref struct_) => Some ( struct_. has_stripped_entries ( ) ) ,
574585 UnionItem ( ref union_) => Some ( union_. has_stripped_entries ( ) ) ,
575586 EnumItem ( ref enum_) => Some ( enum_. has_stripped_entries ( ) ) ,
@@ -612,7 +623,7 @@ impl Item {
612623 }
613624
614625 pub ( crate ) fn is_default ( & self ) -> bool {
615- match * self . kind {
626+ match self . kind {
616627 ItemKind :: MethodItem ( _, Some ( defaultness) ) => {
617628 defaultness. has_value ( ) && !defaultness. is_final ( )
618629 }
@@ -640,7 +651,7 @@ impl Item {
640651 } ;
641652 hir:: FnHeader { safety : sig. safety ( ) , abi : sig. abi ( ) , constness, asyncness }
642653 }
643- let header = match * self . kind {
654+ let header = match self . kind {
644655 ItemKind :: ForeignFunctionItem ( _, safety) => {
645656 let def_id = self . def_id ( ) . unwrap ( ) ;
646657 let abi = tcx. fn_sig ( def_id) . skip_binder ( ) . abi ( ) ;
@@ -679,7 +690,7 @@ impl Item {
679690 ItemId :: DefId ( def_id) => def_id,
680691 } ;
681692
682- match * self . kind {
693+ match self . kind {
683694 // Primitives and Keywords are written in the source code as private modules.
684695 // The modules need to be private so that nobody actually uses them, but the
685696 // keywords and primitives that they are documenting are public.
@@ -2566,13 +2577,13 @@ mod size_asserts {
25662577
25672578 use super :: * ;
25682579 // tidy-alphabetical-start
2569- static_assert_size ! ( Crate , 64 ) ; // frequently moved by-value
2580+ static_assert_size ! ( Crate , 56 ) ; // frequently moved by-value
25702581 static_assert_size ! ( DocFragment , 32 ) ;
25712582 static_assert_size ! ( GenericArg , 32 ) ;
25722583 static_assert_size ! ( GenericArgs , 32 ) ;
25732584 static_assert_size ! ( GenericParamDef , 40 ) ;
25742585 static_assert_size ! ( Generics , 16 ) ;
2575- static_assert_size ! ( Item , 56 ) ;
2586+ static_assert_size ! ( Item , 48 ) ;
25762587 static_assert_size ! ( ItemKind , 48 ) ;
25772588 static_assert_size ! ( PathSegment , 40 ) ;
25782589 static_assert_size ! ( Type , 32 ) ;
0 commit comments