From 32a8dec8898a51832560faa95fb3ed6155f0dc7f Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 20 Nov 2018 21:33:57 +0000 Subject: [PATCH] Clarify undecided semantics --- src/librustc/ty/inhabitedness/mod.rs | 3 +++ src/test/ui/always-inhabited-union-ref.rs | 3 +++ src/test/ui/always-inhabited-union-ref.stderr | 8 ++++---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/librustc/ty/inhabitedness/mod.rs b/src/librustc/ty/inhabitedness/mod.rs index 3f9a9c172026..721d5e14ccc6 100644 --- a/src/librustc/ty/inhabitedness/mod.rs +++ b/src/librustc/ty/inhabitedness/mod.rs @@ -169,6 +169,7 @@ impl<'a, 'gcx, 'tcx> VariantDef { { let is_enum = match adt_kind { // For now, `union`s are never considered uninhabited. + // The precise semantics of inhabitedness with respect to unions is currently undecided. AdtKind::Union => return DefIdForest::empty(), AdtKind::Enum => true, AdtKind::Struct => false, @@ -267,6 +268,8 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> { // References to uninitialised memory is valid for any type, including // uninhabited types, in unsafe code, so we treat all references as // inhabited. + // The precise semantics of inhabitedness with respect to references is currently + // undecided. Ref(..) => DefIdForest::empty(), _ => DefIdForest::empty(), diff --git a/src/test/ui/always-inhabited-union-ref.rs b/src/test/ui/always-inhabited-union-ref.rs index 49ef984eb938..b2f2818cb71b 100644 --- a/src/test/ui/always-inhabited-union-ref.rs +++ b/src/test/ui/always-inhabited-union-ref.rs @@ -1,3 +1,6 @@ +// The precise semantics of inhabitedness with respect to unions and references is currently +// undecided. This test file currently checks a conservative choice. + #![feature(exhaustive_patterns)] #![feature(never_type)] diff --git a/src/test/ui/always-inhabited-union-ref.stderr b/src/test/ui/always-inhabited-union-ref.stderr index 95d3da7be860..bd6179a0b56d 100644 --- a/src/test/ui/always-inhabited-union-ref.stderr +++ b/src/test/ui/always-inhabited-union-ref.stderr @@ -1,23 +1,23 @@ error[E0004]: non-exhaustive patterns: type &'static ! is non-empty - --> $DIR/always-inhabited-union-ref.rs:20:11 + --> $DIR/always-inhabited-union-ref.rs:23:11 | LL | match uninhab_ref() { | ^^^^^^^^^^^^^ | help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms - --> $DIR/always-inhabited-union-ref.rs:20:11 + --> $DIR/always-inhabited-union-ref.rs:23:11 | LL | match uninhab_ref() { | ^^^^^^^^^^^^^ error[E0004]: non-exhaustive patterns: type Foo is non-empty - --> $DIR/always-inhabited-union-ref.rs:24:11 + --> $DIR/always-inhabited-union-ref.rs:27:11 | LL | match uninhab_union() { | ^^^^^^^^^^^^^^^ | help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms - --> $DIR/always-inhabited-union-ref.rs:24:11 + --> $DIR/always-inhabited-union-ref.rs:27:11 | LL | match uninhab_union() { | ^^^^^^^^^^^^^^^