From 2c6bc186100df68ba6dc7e7388e3708af7ba1539 Mon Sep 17 00:00:00 2001 From: Andrew Cann Date: Wed, 18 Jan 2017 15:05:28 +0800 Subject: [PATCH] Feature gate `&Void`'s uninhabitedness. References to empty types are only considered empty if feature(never_type) is enabled. --- src/librustc/ty/inhabitedness/mod.rs | 8 +++++++- ...ninhabited-reference-type-feature-gated.rs | 19 +++++++++++++++++++ src/test/run-pass/empty-types-in-patterns.rs | 5 +++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/uninhabited-reference-type-feature-gated.rs diff --git a/src/librustc/ty/inhabitedness/mod.rs b/src/librustc/ty/inhabitedness/mod.rs index c5b75839e99b7..92395e3c381aa 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 0000000000000..8f246eddbcde4 --- /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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +enum Void {} + +fn main() { + let x: Result = 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 23705d36e3de2..033b185a0ef06 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 = Ok(123); + match x { + Ok(y) => y, + }; + bar(&[]); }