about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2017-01-19 11:56:11 +0100
committerGitHub <noreply@github.com>2017-01-19 11:56:11 +0100
commit87482ee03ad8ffe9df4f593562ff3e71b8344cb7 (patch)
treeab2ca38a6acb7db2e18d76631d6210fe52bb35d7 /src
parentc593ff4ce5672b633129197dabb75d4284575408 (diff)
parent2c6bc186100df68ba6dc7e7388e3708af7ba1539 (diff)
downloadrust-87482ee03ad8ffe9df4f593562ff3e71b8344cb7.tar.gz
rust-87482ee03ad8ffe9df4f593562ff3e71b8344cb7.zip
Rollup merge of #39151 - canndrew:feature-gate-uninhabited-references, r=brson
Feature gate `&Void`'s uninhabitedness.

Here's a totally crazy PR which should never be merged.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/ty/inhabitedness/mod.rs8
-rw-r--r--src/test/compile-fail/uninhabited-reference-type-feature-gated.rs19
-rw-r--r--src/test/run-pass/empty-types-in-patterns.rs5
3 files changed, 31 insertions, 1 deletions
diff --git a/src/librustc/ty/inhabitedness/mod.rs b/src/librustc/ty/inhabitedness/mod.rs
index c5b75839e99..92395e3c381 100644
--- a/src/librustc/ty/inhabitedness/mod.rs
+++ b/src/librustc/ty/inhabitedness/mod.rs
@@ -190,7 +190,13 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
                     ty.uninhabited_from(visited, tcx)
                 }
             }
-            TyRef(_, ref tm) => tm.ty.uninhabited_from(visited, tcx),
+            TyRef(_, ref tm) => {
+                if tcx.sess.features.borrow().never_type {
+                    tm.ty.uninhabited_from(visited, tcx)
+                } else {
+                    DefIdForest::empty()
+                }
+            }
 
             _ => DefIdForest::empty(),
         }
diff --git a/src/test/compile-fail/uninhabited-reference-type-feature-gated.rs b/src/test/compile-fail/uninhabited-reference-type-feature-gated.rs
new file mode 100644
index 00000000000..8f246eddbcd
--- /dev/null
+++ b/src/test/compile-fail/uninhabited-reference-type-feature-gated.rs
@@ -0,0 +1,19 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+enum Void {}
+
+fn main() {
+    let x: Result<u32, &'static Void> = Ok(23);
+    let _ = match x {   //~ ERROR non-exhaustive
+        Ok(n) => n,
+    };
+}
+
diff --git a/src/test/run-pass/empty-types-in-patterns.rs b/src/test/run-pass/empty-types-in-patterns.rs
index 23705d36e3d..033b185a0ef 100644
--- a/src/test/run-pass/empty-types-in-patterns.rs
+++ b/src/test/run-pass/empty-types-in-patterns.rs
@@ -55,6 +55,11 @@ fn main() {
         Err(e) => match e {},
     };
 
+    let x: Result<u32, &!> = Ok(123);
+    match x {
+        Ok(y) => y,
+    };
+
     bar(&[]);
 }