about summary refs log tree commit diff
path: root/src/librustc_const_eval
diff options
context:
space:
mode:
authorAndrew Cann <shum@canndrew.org>2017-01-25 14:48:20 +0800
committerAndrew Cann <shum@canndrew.org>2017-01-25 14:48:20 +0800
commit2b7a23ed304d4298247b030eea0820018c05cd30 (patch)
treeb114ab43f1ea24327ccc255095a1b6978a07c34c /src/librustc_const_eval
parentc0d0e68be4f8bb9d8522bd72a7a1b8ef95b84c6c (diff)
Hide uninhabitedness checks behind feature gate
Diffstat (limited to 'src/librustc_const_eval')
-rw-r--r--src/librustc_const_eval/_match.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/librustc_const_eval/_match.rs b/src/librustc_const_eval/_match.rs
index bb5dacf71e1..1770a112cdf 100644
--- a/src/librustc_const_eval/_match.rs
+++ b/src/librustc_const_eval/_match.rs
@@ -379,19 +379,24 @@ impl<'tcx> Witness<'tcx> {
 fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
                                   pcx: PatternContext<'tcx>) -> Vec<Constructor>
 {
+    let check_inhabited = cx.tcx.sess.features.borrow().never_type;
     debug!("all_constructors({:?})", pcx.ty);
     match pcx.ty.sty {
         ty::TyBool =>
             [true, false].iter().map(|b| ConstantValue(ConstVal::Bool(*b))).collect(),
         ty::TySlice(ref sub_ty) => {
-            if sub_ty.is_uninhabited_from(cx.module, cx.tcx) {
+            if sub_ty.is_uninhabited_from(cx.module, cx.tcx)
+                && check_inhabited
+            {
                 vec![Slice(0)]
             } else {
                 (0..pcx.max_slice_length+1).map(|length| Slice(length)).collect()
             }
         }
         ty::TyArray(ref sub_ty, length) => {
-            if length == 0 || !sub_ty.is_uninhabited_from(cx.module, cx.tcx) {
+            if length == 0 || !(sub_ty.is_uninhabited_from(cx.module, cx.tcx)
+                                && check_inhabited)
+            {
                 vec![Slice(length)]
             } else {
                 vec![]
@@ -403,7 +408,9 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
                 let forest = v.uninhabited_from(&mut visited,
                                                 cx.tcx, substs,
                                                 AdtKind::Enum);
-                if forest.contains(cx.tcx, cx.module) {
+                if forest.contains(cx.tcx, cx.module)
+                    && check_inhabited
+                {
                     None
                 } else {
                     Some(Variant(v.did))
@@ -411,7 +418,9 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
             }).collect()
         }
         _ => {
-            if pcx.ty.is_uninhabited_from(cx.module, cx.tcx) {
+            if pcx.ty.is_uninhabited_from(cx.module, cx.tcx)
+                    && check_inhabited
+            {
                 vec![]
             } else {
                 vec![Single]