Skip to content

Commit f4aa00b

Browse files
committed
rustc_typeck: fix the generics for (const-generic) N expression in e.g. [T; N].
1 parent 7d9af83 commit f4aa00b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/librustc_typeck/collect.rs

+14
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,20 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::Generics {
900900
let parent_id = tcx.hir().get_parent_item(hir_id);
901901
Some(tcx.hir().local_def_id(parent_id))
902902
}
903+
// FIXME(#43408) enable this in all cases when we get lazy normalization.
904+
Node::AnonConst(&anon_const) => {
905+
// HACK(eddyb) this provides the correct generics when the workaround
906+
// for a const parameter `AnonConst` is being used elsewhere, as then
907+
// there won't be the kind of cyclic dependency blocking #43408.
908+
let expr = &tcx.hir().body(anon_const.body).value;
909+
let icx = ItemCtxt::new(tcx, def_id);
910+
if AstConv::const_param_def_id(&icx, expr).is_some() {
911+
let parent_id = tcx.hir().get_parent_item(hir_id);
912+
Some(tcx.hir().local_def_id(parent_id))
913+
} else {
914+
None
915+
}
916+
}
903917
Node::Expr(&hir::Expr {
904918
node: hir::ExprKind::Closure(..),
905919
..

0 commit comments

Comments
 (0)