@@ -35,6 +35,12 @@ pub(crate) fn collect_definitions(
35
35
struct DefCollector < ' a , ' b , ' tcx > {
36
36
resolver : & ' a mut Resolver < ' b , ' tcx > ,
37
37
parent_def : LocalDefId ,
38
+ /// If we have an anon const that consists of a macro invocation, e.g. `Foo<{ m!() }>`,
39
+ /// we need to wait until we know what the macro expands to before we create the def for
40
+ /// the anon const. That's because we lower some anon consts into `hir::ConstArgKind::Path`,
41
+ /// which don't have defs.
42
+ ///
43
+ /// See [`Self::visit_anon_const`].
38
44
pending_anon_const_info : Option < PendingAnonConstInfo > ,
39
45
impl_trait_context : ImplTraitContext ,
40
46
in_attr : bool ,
@@ -335,7 +341,9 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
335
341
// def. we'll then create a def later in ast lowering in this case. the parent of nested
336
342
// items will be messed up, but that's ok because there can't be any if we're just looking
337
343
// for bare idents.
344
+
338
345
if matches ! ( constant. value. maybe_unwrap_block( ) . kind, ExprKind :: MacCall ( ..) ) {
346
+ // See self.pending_anon_const_info for explanation
339
347
self . pending_anon_const_info =
340
348
Some ( PendingAnonConstInfo { id : constant. id , span : constant. value . span } ) ;
341
349
visit:: walk_anon_const ( self , constant)
@@ -353,8 +361,8 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
353
361
return self . visit_macro_invoc ( expr. id ) ;
354
362
}
355
363
356
- let grandparent_def = if let Some ( pending_anon) = self . pending_anon_const_info {
357
- self . pending_anon_const_info = None ;
364
+ let grandparent_def = if let Some ( pending_anon) = self . pending_anon_const_info . take ( ) {
365
+ // See self.pending_anon_const_info for explanation
358
366
if !expr. is_potential_trivial_const_arg ( ) {
359
367
self . create_def ( pending_anon. id , kw:: Empty , DefKind :: AnonConst , pending_anon. span )
360
368
} else {
0 commit comments