@@ -320,10 +320,7 @@ pub(crate) struct Item {
320320 /// The name of this item.
321321 /// Optional because not every item has a name, e.g. impls.
322322 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 > ,
327324 pub ( crate ) item_id : ItemId ,
328325 /// This is the `LocalDefId` of the `use` statement if the item was inlined.
329326 /// The crate metadata doesn't hold this information, so the `use` statement
@@ -332,6 +329,21 @@ pub(crate) struct Item {
332329 pub ( crate ) cfg : Option < Arc < Cfg > > ,
333330}
334331
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+
335347/// NOTE: this does NOT unconditionally print every item, to avoid thousands of lines of logs.
336348/// If you want to see the debug output for attributes and the `kind` as well, use `{:#?}` instead of `{:?}`.
337349impl fmt:: Debug for Item {
@@ -391,9 +403,9 @@ impl Item {
391403 }
392404
393405 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 ,
397409 } ;
398410 match kind {
399411 ItemKind :: ModuleItem ( Module { span, .. } ) => Some ( * span) ,
@@ -438,7 +450,7 @@ impl Item {
438450 def_id,
439451 name,
440452 kind,
441- Box :: new ( Attributes :: from_ast ( ast_attrs) ) ,
453+ Attributes :: from_ast ( ast_attrs) ,
442454 ast_attrs. cfg ( cx. tcx , & cx. cache . hidden_cfg ) ,
443455 )
444456 }
@@ -447,16 +459,15 @@ impl Item {
447459 def_id : DefId ,
448460 name : Option < Symbol > ,
449461 kind : ItemKind ,
450- attrs : Box < Attributes > ,
462+ attrs : Attributes ,
451463 cfg : Option < Arc < Cfg > > ,
452464 ) -> Item {
453465 trace ! ( "name={name:?}, def_id={def_id:?} cfg={cfg:?}" ) ;
454466
455467 Item {
456468 item_id : def_id. into ( ) ,
457- kind : Box :: new ( kind) ,
469+ inner : Box :: new ( ItemInner { kind, attrs } ) ,
458470 name,
459- attrs,
460471 cfg,
461472 inline_stmt_id : None ,
462473 }
@@ -524,16 +535,16 @@ impl Item {
524535 self . type_ ( ) == ItemType :: Variant
525536 }
526537 pub ( crate ) fn is_associated_type ( & self ) -> bool {
527- matches ! ( & * self . kind, AssocTypeItem ( ..) | StrippedItem ( box AssocTypeItem ( ..) ) )
538+ matches ! ( self . kind, AssocTypeItem ( ..) | StrippedItem ( box AssocTypeItem ( ..) ) )
528539 }
529540 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 ( ..) ) )
531542 }
532543 pub ( crate ) fn is_associated_const ( & self ) -> bool {
533- matches ! ( & * self . kind, AssocConstItem ( ..) | StrippedItem ( box AssocConstItem ( ..) ) )
544+ matches ! ( self . kind, AssocConstItem ( ..) | StrippedItem ( box AssocConstItem ( ..) ) )
534545 }
535546 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 ( ..) ) )
537548 }
538549 pub ( crate ) fn is_method ( & self ) -> bool {
539550 self . type_ ( ) == ItemType :: Method
@@ -557,14 +568,14 @@ impl Item {
557568 self . type_ ( ) == ItemType :: Keyword
558569 }
559570 pub ( crate ) fn is_stripped ( & self ) -> bool {
560- match * self . kind {
571+ match self . kind {
561572 StrippedItem ( ..) => true ,
562573 ImportItem ( ref i) => !i. should_be_displayed ,
563574 _ => false ,
564575 }
565576 }
566577 pub ( crate ) fn has_stripped_entries ( & self ) -> Option < bool > {
567- match * self . kind {
578+ match self . kind {
568579 StructItem ( ref struct_) => Some ( struct_. has_stripped_entries ( ) ) ,
569580 UnionItem ( ref union_) => Some ( union_. has_stripped_entries ( ) ) ,
570581 EnumItem ( ref enum_) => Some ( enum_. has_stripped_entries ( ) ) ,
@@ -607,7 +618,7 @@ impl Item {
607618 }
608619
609620 pub ( crate ) fn is_default ( & self ) -> bool {
610- match * self . kind {
621+ match self . kind {
611622 ItemKind :: MethodItem ( _, Some ( defaultness) ) => {
612623 defaultness. has_value ( ) && !defaultness. is_final ( )
613624 }
@@ -635,7 +646,7 @@ impl Item {
635646 } ;
636647 hir:: FnHeader { safety : sig. safety ( ) , abi : sig. abi ( ) , constness, asyncness }
637648 }
638- let header = match * self . kind {
649+ let header = match self . kind {
639650 ItemKind :: ForeignFunctionItem ( _, safety) => {
640651 let def_id = self . def_id ( ) . unwrap ( ) ;
641652 let abi = tcx. fn_sig ( def_id) . skip_binder ( ) . abi ( ) ;
@@ -674,7 +685,7 @@ impl Item {
674685 ItemId :: DefId ( def_id) => def_id,
675686 } ;
676687
677- match * self . kind {
688+ match self . kind {
678689 // Primitives and Keywords are written in the source code as private modules.
679690 // The modules need to be private so that nobody actually uses them, but the
680691 // keywords and primitives that they are documenting are public.
@@ -2561,13 +2572,13 @@ mod size_asserts {
25612572
25622573 use super :: * ;
25632574 // tidy-alphabetical-start
2564- static_assert_size ! ( Crate , 64 ) ; // frequently moved by-value
2575+ static_assert_size ! ( Crate , 56 ) ; // frequently moved by-value
25652576 static_assert_size ! ( DocFragment , 32 ) ;
25662577 static_assert_size ! ( GenericArg , 32 ) ;
25672578 static_assert_size ! ( GenericArgs , 32 ) ;
25682579 static_assert_size ! ( GenericParamDef , 40 ) ;
25692580 static_assert_size ! ( Generics , 16 ) ;
2570- static_assert_size ! ( Item , 56 ) ;
2581+ static_assert_size ! ( Item , 48 ) ;
25712582 static_assert_size ! ( ItemKind , 48 ) ;
25722583 static_assert_size ! ( PathSegment , 40 ) ;
25732584 static_assert_size ! ( Type , 32 ) ;
0 commit comments