@@ -835,17 +835,16 @@ pub struct OwnerNodes<'tcx> {
835835 // The zeroth node's parent should never be accessed: the owner's parent is computed by the
836836 // hir_owner_parent query. It is set to `ItemLocalId::INVALID` to force an ICE if accidentally
837837 // used.
838- pub nodes : IndexVec < ItemLocalId , Option < ParentedNode < ' tcx > > > ,
838+ pub nodes : IndexVec < ItemLocalId , ParentedNode < ' tcx > > ,
839839 /// Content of local bodies.
840840 pub bodies : SortedMap < ItemLocalId , & ' tcx Body < ' tcx > > ,
841841}
842842
843843impl < ' tcx > OwnerNodes < ' tcx > {
844844 pub fn node ( & self ) -> OwnerNode < ' tcx > {
845845 use rustc_index:: Idx ;
846- let node = self . nodes [ ItemLocalId :: new ( 0 ) ] . as_ref ( ) . unwrap ( ) . node ;
847- let node = node. as_owner ( ) . unwrap ( ) ; // Indexing must ensure it is an OwnerNode.
848- node
846+ // Indexing must ensure it is an OwnerNode.
847+ self . nodes [ ItemLocalId :: new ( 0 ) ] . node . as_owner ( ) . unwrap ( )
849848 }
850849}
851850
@@ -860,9 +859,7 @@ impl fmt::Debug for OwnerNodes<'_> {
860859 . nodes
861860 . iter_enumerated ( )
862861 . map ( |( id, parented_node) | {
863- let parented_node = parented_node. as_ref ( ) . map ( |node| node. parent ) ;
864-
865- debug_fn ( move |f| write ! ( f, "({id:?}, {parented_node:?})" ) )
862+ debug_fn ( move |f| write ! ( f, "({id:?}, {:?})" , parented_node. parent) )
866863 } )
867864 . collect :: < Vec < _ > > ( ) ,
868865 )
@@ -3356,13 +3353,14 @@ impl<'hir> OwnerNode<'hir> {
33563353 }
33573354 }
33583355
3359- pub fn span ( & self ) -> Span {
3356+ #[ allow( rustc:: pass_by_value) ]
3357+ pub fn span ( & self ) -> & ' hir Span {
33603358 match self {
33613359 OwnerNode :: Item ( Item { span, .. } )
33623360 | OwnerNode :: ForeignItem ( ForeignItem { span, .. } )
33633361 | OwnerNode :: ImplItem ( ImplItem { span, .. } )
3364- | OwnerNode :: TraitItem ( TraitItem { span, .. } ) => * span,
3365- OwnerNode :: Crate ( Mod { spans : ModSpans { inner_span, .. } , .. } ) => * inner_span,
3362+ | OwnerNode :: TraitItem ( TraitItem { span, .. } ) => span,
3363+ OwnerNode :: Crate ( Mod { spans : ModSpans { inner_span, .. } , .. } ) => inner_span,
33663364 }
33673365 }
33683366
@@ -3491,17 +3489,20 @@ pub enum Node<'hir> {
34913489 Arm ( & ' hir Arm < ' hir > ) ,
34923490 Block ( & ' hir Block < ' hir > ) ,
34933491 Local ( & ' hir Local < ' hir > ) ,
3494-
34953492 /// `Ctor` refers to the constructor of an enum variant or struct. Only tuple or unit variants
34963493 /// with synthesized constructors.
34973494 Ctor ( & ' hir VariantData < ' hir > ) ,
3498-
34993495 Lifetime ( & ' hir Lifetime ) ,
35003496 GenericParam ( & ' hir GenericParam < ' hir > ) ,
3501-
35023497 Crate ( & ' hir Mod < ' hir > ) ,
3503-
35043498 Infer ( & ' hir InferArg ) ,
3499+ WhereBoundPredicate ( & ' hir WhereBoundPredicate < ' hir > ) ,
3500+ Let ( & ' hir Let < ' hir > ) ,
3501+ // Span by reference to minimize `Node`'s size
3502+ #[ allow( rustc:: pass_by_value) ]
3503+ ArrayLenInfer ( & ' hir Span ) ,
3504+ #[ allow( rustc:: pass_by_value) ]
3505+ Err ( & ' hir Span ) ,
35053506}
35063507
35073508impl < ' hir > Node < ' hir > {
@@ -3546,7 +3547,11 @@ impl<'hir> Node<'hir> {
35463547 | Node :: Crate ( ..)
35473548 | Node :: Ty ( ..)
35483549 | Node :: TraitRef ( ..)
3549- | Node :: Infer ( ..) => None ,
3550+ | Node :: Infer ( ..)
3551+ | Node :: WhereBoundPredicate ( ..)
3552+ | Node :: Let ( ..)
3553+ | Node :: ArrayLenInfer ( ..)
3554+ | Node :: Err ( ..) => None ,
35503555 }
35513556 }
35523557
0 commit comments