about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2017-11-26 20:05:18 -0500
committerNiko Matsakis <niko@alum.mit.edu>2017-12-13 06:03:25 -0500
commit7f20b9142d278c0ce68e7ce48e3ef92201c61ab4 (patch)
tree6d6f6709ab121755e596365dd4e2e8dd6dca5390
parentd6772cb972a5ca531ecbe45ad779bafe33895caa (diff)
downloadrust-7f20b9142d278c0ce68e7ce48e3ef92201c61ab4.tar.gz
rust-7f20b9142d278c0ce68e7ce48e3ef92201c61ab4.zip
fix universal regions to handle constant expressions like `[T; 22]`
-rw-r--r--src/librustc_mir/borrow_check/nll/universal_regions.rs32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/librustc_mir/borrow_check/nll/universal_regions.rs b/src/librustc_mir/borrow_check/nll/universal_regions.rs
index 857a620cead..c8b5a258a70 100644
--- a/src/librustc_mir/borrow_check/nll/universal_regions.rs
+++ b/src/librustc_mir/borrow_check/nll/universal_regions.rs
@@ -493,7 +493,27 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
                 substs.substs
             }
             ty::TyFnDef(_, substs) => substs,
-            _ => bug!(),
+
+            // FIXME. When we encounter other sorts of constant
+            // expressions, such as the `22` in `[foo; 22]`, we can
+            // get the type `usize` here. For now, just return an
+            // empty vector of substs in this case, since there are no
+            // generics in scope in such expressions right now.
+            //
+            // Eventually I imagine we could get a wider range of
+            // types.  What is the best way to handle this? Should we
+            // be checking something other than the type of the def-id
+            // to figure out what to do (e.g. the def-key?).
+            ty::TyUint(..) => {
+                assert!(identity_substs.is_empty());
+                identity_substs
+            }
+
+            _ => span_bug!(
+                tcx.def_span(self.mir_def_id),
+                "unknown defining type: {:?}",
+                defining_ty
+            ),
         };
 
         let global_mapping = iter::once((gcx.types.re_static, fr_static));
@@ -551,7 +571,15 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
             ty::TyFnDef(def_id, _) => {
                 let sig = tcx.fn_sig(def_id);
                 let sig = indices.fold_to_region_vids(tcx, &sig);
-                return sig.inputs_and_output();
+                sig.inputs_and_output()
+            }
+
+            // FIXME: as above, this happens on things like `[foo;
+            // 22]`. For now, no inputs, one output, but it seems like
+            // we need a more general way to handle this category of
+            // MIR.
+            ty::TyUint(..) => {
+                ty::Binder::dummy(tcx.mk_type_list(iter::once(defining_ty)))
             }
 
             _ => span_bug!(