Skip to content

Commit 7f20b91

Browse files
committed
fix universal regions to handle constant expressions like [T; 22]
1 parent d6772cb commit 7f20b91

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/librustc_mir/borrow_check/nll/universal_regions.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,27 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
493493
substs.substs
494494
}
495495
ty::TyFnDef(_, substs) => substs,
496-
_ => bug!(),
496+
497+
// FIXME. When we encounter other sorts of constant
498+
// expressions, such as the `22` in `[foo; 22]`, we can
499+
// get the type `usize` here. For now, just return an
500+
// empty vector of substs in this case, since there are no
501+
// generics in scope in such expressions right now.
502+
//
503+
// Eventually I imagine we could get a wider range of
504+
// types. What is the best way to handle this? Should we
505+
// be checking something other than the type of the def-id
506+
// to figure out what to do (e.g. the def-key?).
507+
ty::TyUint(..) => {
508+
assert!(identity_substs.is_empty());
509+
identity_substs
510+
}
511+
512+
_ => span_bug!(
513+
tcx.def_span(self.mir_def_id),
514+
"unknown defining type: {:?}",
515+
defining_ty
516+
),
497517
};
498518

499519
let global_mapping = iter::once((gcx.types.re_static, fr_static));
@@ -551,7 +571,15 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
551571
ty::TyFnDef(def_id, _) => {
552572
let sig = tcx.fn_sig(def_id);
553573
let sig = indices.fold_to_region_vids(tcx, &sig);
554-
return sig.inputs_and_output();
574+
sig.inputs_and_output()
575+
}
576+
577+
// FIXME: as above, this happens on things like `[foo;
578+
// 22]`. For now, no inputs, one output, but it seems like
579+
// we need a more general way to handle this category of
580+
// MIR.
581+
ty::TyUint(..) => {
582+
ty::Binder::dummy(tcx.mk_type_list(iter::once(defining_ty)))
555583
}
556584

557585
_ => span_bug!(

0 commit comments

Comments
 (0)