@@ -509,6 +509,23 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
509509 def_id
510510 }
511511
512+ // HACK: See `DefCollector::handle_lazy_anon_const_def` for why this is necessary.
513+ fn create_or_reuse_anon_const_def (
514+ & mut self ,
515+ parent : LocalDefId ,
516+ node_id : ast:: NodeId ,
517+ name : Symbol ,
518+ def_kind : DefKind ,
519+ span : Span ,
520+ ) -> LocalDefId {
521+ debug_assert_eq ! ( def_kind, DefKind :: AnonConst ) ;
522+ if let Some ( def_id) = self . opt_local_def_id ( node_id) {
523+ def_id
524+ } else {
525+ self . create_def ( parent, node_id, name, def_kind, span)
526+ }
527+ }
528+
512529 fn next_node_id ( & mut self ) -> NodeId {
513530 let start = self . resolver . next_node_id ;
514531 let next = start. as_u32 ( ) . checked_add ( 1 ) . expect ( "input too large; ran out of NodeIds" ) ;
@@ -2181,19 +2198,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21812198 /// See [`hir::ConstArg`] for when to use this function vs
21822199 /// [`Self::lower_anon_const_to_const_arg`].
21832200 fn lower_anon_const_to_anon_const ( & mut self , c : & AnonConst ) -> & ' hir hir:: AnonConst {
2184- if c. value . is_potential_trivial_const_arg ( true ) {
2185- // HACK(min_generic_const_args): see DefCollector::visit_anon_const
2186- // Over there, we guess if this is a bare param and only create a def if
2187- // we think it's not. However we may can guess wrong (see there for example)
2188- // in which case we have to create the def here.
2189- self . create_def (
2190- self . current_def_id_parent ,
2191- c. id ,
2192- kw:: Empty ,
2193- DefKind :: AnonConst ,
2194- c. value . span ,
2195- ) ;
2196- }
2201+ self . create_or_reuse_anon_const_def (
2202+ self . current_def_id_parent ,
2203+ c. id ,
2204+ kw:: Empty ,
2205+ DefKind :: AnonConst ,
2206+ c. value . span ,
2207+ ) ;
21972208
21982209 self . arena . alloc ( self . with_new_scopes ( c. value . span , |this| {
21992210 let def_id = this. local_def_id ( c. id ) ;
0 commit comments