@@ -117,18 +117,6 @@ struct LoweringContext<'a, 'hir> {
117
117
is_in_dyn_type : bool ,
118
118
119
119
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 ,
132
120
item_local_id_counter : hir:: ItemLocalId ,
133
121
trait_map : ItemLocalMap < Box < [ TraitCandidate ] > > ,
134
122
@@ -161,7 +149,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
161
149
attrs : SortedMap :: default ( ) ,
162
150
children : Vec :: default ( ) ,
163
151
current_hir_id_owner : hir:: CRATE_OWNER_ID ,
164
- current_def_id_parent : CRATE_DEF_ID ,
165
152
item_local_id_counter : hir:: ItemLocalId :: ZERO ,
166
153
ident_and_label_to_local_id : Default :: default ( ) ,
167
154
#[ cfg( debug_assertions) ]
@@ -565,7 +552,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
565
552
debug_assert_eq ! ( _old, None ) ;
566
553
}
567
554
568
- let item = self . with_def_id_parent ( def_id , f ) ;
555
+ let item = f ( self ) ;
569
556
debug_assert_eq ! ( def_id, item. def_id( ) . def_id) ;
570
557
// `f` should have consumed all the elements in these vectors when constructing `item`.
571
558
debug_assert ! ( self . impl_trait_defs. is_empty( ) ) ;
@@ -590,13 +577,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
590
577
self . children . push ( ( def_id, hir:: MaybeOwner :: Owner ( info) ) ) ;
591
578
}
592
579
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
-
600
580
fn make_owner_info ( & mut self , node : hir:: OwnerNode < ' hir > ) -> & ' hir hir:: OwnerInfo < ' hir > {
601
581
let attrs = std:: mem:: take ( & mut self . attrs ) ;
602
582
let mut bodies = std:: mem:: take ( & mut self . bodies ) ;
@@ -773,7 +753,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
773
753
LifetimeRes :: Fresh { param, kind, .. } => {
774
754
// Late resolution delegates to us the creation of the `LocalDefId`.
775
755
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 ,
777
757
param,
778
758
kw:: UnderscoreLifetime ,
779
759
DefKind :: LifetimeParam ,
@@ -1466,17 +1446,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1466
1446
let opaque_ty_hir_id = self . lower_node_id ( opaque_ty_node_id) ;
1467
1447
debug ! ( ?opaque_ty_def_id, ?opaque_ty_hir_id) ;
1468
1448
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) ;
1480
1458
1481
1459
hir:: TyKind :: OpaqueDef ( opaque_ty_def)
1482
1460
}
@@ -2084,7 +2062,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2084
2062
} else {
2085
2063
// Construct an AnonConst where the expr is the "ty"'s path.
2086
2064
2087
- let parent_def_id = self . current_def_id_parent ;
2065
+ let parent_def_id = self . current_hir_id_owner . def_id ;
2088
2066
let node_id = self . next_node_id ( ) ;
2089
2067
let span = self . lower_span ( span) ;
2090
2068
@@ -2108,9 +2086,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2108
2086
self . arena . alloc ( hir:: AnonConst {
2109
2087
def_id,
2110
2088
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) ) ,
2114
2090
span,
2115
2091
} )
2116
2092
} ) ;
@@ -2159,7 +2135,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2159
2135
None ,
2160
2136
) ;
2161
2137
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
+ } ;
2163
2142
}
2164
2143
2165
2144
let lowered_anon = self . lower_anon_const_to_anon_const ( anon) ;
@@ -2169,29 +2148,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2169
2148
/// See [`hir::ConstArg`] for when to use this function vs
2170
2149
/// [`Self::lower_anon_const_to_const_arg`].
2171
2150
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
-
2186
2151
self . arena . alloc ( self . with_new_scopes ( c. value . span , |this| {
2187
2152
let def_id = this. local_def_id ( c. id ) ;
2188
2153
let hir_id = this. lower_node_id ( c. id ) ;
2189
2154
hir:: AnonConst {
2190
2155
def_id,
2191
2156
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 ) ) ,
2195
2158
span : this. lower_span ( c. value . span ) ,
2196
2159
}
2197
2160
} ) )
0 commit comments