@@ -117,18 +117,6 @@ struct LoweringContext<'a, 'hir> {
117117 is_in_dyn_type : bool ,
118118
119119 current_hir_id_owner : hir:: OwnerId ,
120- /// Why do we need this in addition to [`Self::current_hir_id_owner`]?
121- ///
122- /// Currently (as of June 2024), anonymous constants are not HIR owners; however,
123- /// they do get their own DefIds. Some of these DefIds have to be created during
124- /// AST lowering, rather than def collection, because we can't tell until after
125- /// name resolution whether an anonymous constant will end up instead being a
126- /// [`hir::ConstArgKind::Path`]. However, to compute which generics are
127- /// available to an anonymous constant nested inside another, we need to make
128- /// sure that the parent is recorded as the parent anon const, not the enclosing
129- /// item. So we need to track parent defs differently from HIR owners, since they
130- /// will be finer-grained in the case of anon consts.
131- current_def_id_parent : LocalDefId ,
132120 item_local_id_counter : hir:: ItemLocalId ,
133121 trait_map : ItemLocalMap < Box < [ TraitCandidate ] > > ,
134122
@@ -161,7 +149,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
161149 attrs : SortedMap :: default ( ) ,
162150 children : Vec :: default ( ) ,
163151 current_hir_id_owner : hir:: CRATE_OWNER_ID ,
164- current_def_id_parent : CRATE_DEF_ID ,
165152 item_local_id_counter : hir:: ItemLocalId :: ZERO ,
166153 ident_and_label_to_local_id : Default :: default ( ) ,
167154 #[ cfg( debug_assertions) ]
@@ -565,7 +552,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
565552 debug_assert_eq ! ( _old, None ) ;
566553 }
567554
568- let item = self . with_def_id_parent ( def_id , f ) ;
555+ let item = f ( self ) ;
569556 debug_assert_eq ! ( def_id, item. def_id( ) . def_id) ;
570557 // `f` should have consumed all the elements in these vectors when constructing `item`.
571558 debug_assert ! ( self . impl_trait_defs. is_empty( ) ) ;
@@ -590,13 +577,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
590577 self . children . push ( ( def_id, hir:: MaybeOwner :: Owner ( info) ) ) ;
591578 }
592579
593- fn with_def_id_parent < T > ( & mut self , parent : LocalDefId , f : impl FnOnce ( & mut Self ) -> T ) -> T {
594- let current_def_id_parent = std:: mem:: replace ( & mut self . current_def_id_parent , parent) ;
595- let result = f ( self ) ;
596- self . current_def_id_parent = current_def_id_parent;
597- result
598- }
599-
600580 fn make_owner_info ( & mut self , node : hir:: OwnerNode < ' hir > ) -> & ' hir hir:: OwnerInfo < ' hir > {
601581 let attrs = std:: mem:: take ( & mut self . attrs ) ;
602582 let mut bodies = std:: mem:: take ( & mut self . bodies ) ;
@@ -773,7 +753,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
773753 LifetimeRes :: Fresh { param, kind, .. } => {
774754 // Late resolution delegates to us the creation of the `LocalDefId`.
775755 let _def_id = self . create_def (
776- self . current_hir_id_owner . def_id , // FIXME: should this use self.current_def_id_parent?
756+ self . current_hir_id_owner . def_id ,
777757 param,
778758 kw:: UnderscoreLifetime ,
779759 DefKind :: LifetimeParam ,
@@ -1466,17 +1446,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14661446 let opaque_ty_hir_id = self . lower_node_id ( opaque_ty_node_id) ;
14671447 debug ! ( ?opaque_ty_def_id, ?opaque_ty_hir_id) ;
14681448
1469- let opaque_ty_def = self . with_def_id_parent ( opaque_ty_def_id, |this| {
1470- let bounds = lower_item_bounds ( this) ;
1471- let opaque_ty_def = hir:: OpaqueTy {
1472- hir_id : opaque_ty_hir_id,
1473- def_id : opaque_ty_def_id,
1474- bounds,
1475- origin,
1476- span : this. lower_span ( opaque_ty_span) ,
1477- } ;
1478- this. arena . alloc ( opaque_ty_def)
1479- } ) ;
1449+ let bounds = lower_item_bounds ( self ) ;
1450+ let opaque_ty_def = hir:: OpaqueTy {
1451+ hir_id : opaque_ty_hir_id,
1452+ def_id : opaque_ty_def_id,
1453+ bounds,
1454+ origin,
1455+ span : self . lower_span ( opaque_ty_span) ,
1456+ } ;
1457+ let opaque_ty_def = self . arena . alloc ( opaque_ty_def) ;
14801458
14811459 hir:: TyKind :: OpaqueDef ( opaque_ty_def)
14821460 }
@@ -2084,7 +2062,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20842062 } else {
20852063 // Construct an AnonConst where the expr is the "ty"'s path.
20862064
2087- let parent_def_id = self . current_def_id_parent ;
2065+ let parent_def_id = self . current_hir_id_owner . def_id ;
20882066 let node_id = self . next_node_id ( ) ;
20892067 let span = self . lower_span ( span) ;
20902068
@@ -2108,9 +2086,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21082086 self . arena . alloc ( hir:: AnonConst {
21092087 def_id,
21102088 hir_id,
2111- body : this. with_def_id_parent ( def_id, |this| {
2112- this. lower_const_body ( path_expr. span , Some ( & path_expr) )
2113- } ) ,
2089+ body : this. lower_const_body ( path_expr. span , Some ( & path_expr) ) ,
21142090 span,
21152091 } )
21162092 } ) ;
@@ -2159,7 +2135,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21592135 None ,
21602136 ) ;
21612137
2162- return ConstArg { hir_id : self . next_id ( ) , kind : hir:: ConstArgKind :: Path ( qpath) } ;
2138+ return ConstArg {
2139+ hir_id : self . lower_node_id ( anon. id ) ,
2140+ kind : hir:: ConstArgKind :: Path ( qpath) ,
2141+ } ;
21632142 }
21642143
21652144 let lowered_anon = self . lower_anon_const_to_anon_const ( anon) ;
@@ -2169,29 +2148,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21692148 /// See [`hir::ConstArg`] for when to use this function vs
21702149 /// [`Self::lower_anon_const_to_const_arg`].
21712150 fn lower_anon_const_to_anon_const ( & mut self , c : & AnonConst ) -> & ' hir hir:: AnonConst {
2172- if c. value . is_potential_trivial_const_arg ( true ) {
2173- // HACK(min_generic_const_args): see DefCollector::visit_anon_const
2174- // Over there, we guess if this is a bare param and only create a def if
2175- // we think it's not. However we may can guess wrong (see there for example)
2176- // in which case we have to create the def here.
2177- self . create_def (
2178- self . current_def_id_parent ,
2179- c. id ,
2180- kw:: Empty ,
2181- DefKind :: AnonConst ,
2182- c. value . span ,
2183- ) ;
2184- }
2185-
21862151 self . arena . alloc ( self . with_new_scopes ( c. value . span , |this| {
21872152 let def_id = this. local_def_id ( c. id ) ;
21882153 let hir_id = this. lower_node_id ( c. id ) ;
21892154 hir:: AnonConst {
21902155 def_id,
21912156 hir_id,
2192- body : this. with_def_id_parent ( def_id, |this| {
2193- this. lower_const_body ( c. value . span , Some ( & c. value ) )
2194- } ) ,
2157+ body : this. lower_const_body ( c. value . span , Some ( & c. value ) ) ,
21952158 span : this. lower_span ( c. value . span ) ,
21962159 }
21972160 } ) )
0 commit comments