Skip to content

Commit 8169bae

Browse files
committed
DefCollector stuff
1 parent c635ab7 commit 8169bae

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

compiler/rustc_resolve/src/def_collector.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -367,15 +367,16 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
367367
}
368368

369369
fn visit_anon_const(&mut self, constant: &'a AnonConst) {
370+
// `MgcaDisambiguation::Direct` is set even when MGCA is disabled, so
371+
// to avoid affecting stable we have to feature gate the not creating
372+
// anon consts
373+
if !self.resolver.tcx.features().min_generic_const_args() {
374+
let parent =
375+
self.create_def(constant.id, None, DefKind::AnonConst, constant.value.span);
376+
return self.with_parent(parent, |this| visit::walk_anon_const(this, constant));
377+
}
378+
370379
match constant.mgca_disambiguation {
371-
// `MgcaDisambiguation::Direct` is set even when MGCA is disabled, so
372-
// to avoid affecting stable we have to feature gate the not creating
373-
// anon consts
374-
_ if !self.resolver.tcx.features().min_generic_const_args() => {
375-
let parent =
376-
self.create_def(constant.id, None, DefKind::AnonConst, constant.value.span);
377-
self.with_parent(parent, |this| visit::walk_anon_const(this, constant));
378-
}
379380
MgcaDisambiguation::Direct => self.with_const_arg(ConstArgContext::Direct, |this| {
380381
visit::walk_anon_const(this, constant);
381382
}),
@@ -421,28 +422,23 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
421422
ExprKind::Struct(_) => return visit::walk_expr(self, expr),
422423
// FIXME(mgca): we may want to handle block labels in some manner
423424
ExprKind::Block(block, _) if let [stmt] = block.stmts.as_slice() => match stmt.kind {
424-
StmtKind::Let(..) | StmtKind::Item(..) | StmtKind::Semi(..) | StmtKind::Empty => {
425-
return self.with_const_arg(ConstArgContext::NonDirect, |this| {
426-
visit::walk_expr(this, expr)
427-
});
428-
}
429-
430425
// FIXME(mgca): this probably means that mac calls that expand
431426
// to semi'd const blocks are handled differently to just writing
432427
// out a semi'd const block.
433-
StmtKind::Expr(..) | StmtKind::MacCall(..) => {
434-
return visit::walk_expr(self, expr);
428+
StmtKind::Expr(..) | StmtKind::MacCall(..) => return visit::walk_expr(self, expr),
429+
430+
// Fallback to normal behaviour
431+
StmtKind::Let(..) | StmtKind::Item(..) | StmtKind::Semi(..) | StmtKind::Empty => {
432+
self.invocation_parent.parent_def
435433
}
436434
},
437435

438-
_ => {
439-
return self.with_const_arg(ConstArgContext::NonDirect, |this| {
440-
visit::walk_expr(this, expr)
441-
});
442-
}
436+
_ => self.invocation_parent.parent_def,
443437
};
444438

445439
self.with_const_arg(ConstArgContext::NonDirect, |this| {
440+
// Note in some cases the `parent_def` here may be the existing parent
441+
// and this is actually a no-op `with_parent` call.
446442
this.with_parent(parent_def, |this| visit::walk_expr(this, expr))
447443
})
448444
}

0 commit comments

Comments
 (0)