Skip to content

Commit 32a8dec

Browse files
committed
Clarify undecided semantics
1 parent d2b3407 commit 32a8dec

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/librustc/ty/inhabitedness/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ impl<'a, 'gcx, 'tcx> VariantDef {
169169
{
170170
let is_enum = match adt_kind {
171171
// For now, `union`s are never considered uninhabited.
172+
// The precise semantics of inhabitedness with respect to unions is currently undecided.
172173
AdtKind::Union => return DefIdForest::empty(),
173174
AdtKind::Enum => true,
174175
AdtKind::Struct => false,
@@ -267,6 +268,8 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
267268
// References to uninitialised memory is valid for any type, including
268269
// uninhabited types, in unsafe code, so we treat all references as
269270
// inhabited.
271+
// The precise semantics of inhabitedness with respect to references is currently
272+
// undecided.
270273
Ref(..) => DefIdForest::empty(),
271274

272275
_ => DefIdForest::empty(),

src/test/ui/always-inhabited-union-ref.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// The precise semantics of inhabitedness with respect to unions and references is currently
2+
// undecided. This test file currently checks a conservative choice.
3+
14
#![feature(exhaustive_patterns)]
25
#![feature(never_type)]
36

src/test/ui/always-inhabited-union-ref.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error[E0004]: non-exhaustive patterns: type &'static ! is non-empty
2-
--> $DIR/always-inhabited-union-ref.rs:20:11
2+
--> $DIR/always-inhabited-union-ref.rs:23:11
33
|
44
LL | match uninhab_ref() {
55
| ^^^^^^^^^^^^^
66
|
77
help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
8-
--> $DIR/always-inhabited-union-ref.rs:20:11
8+
--> $DIR/always-inhabited-union-ref.rs:23:11
99
|
1010
LL | match uninhab_ref() {
1111
| ^^^^^^^^^^^^^
1212

1313
error[E0004]: non-exhaustive patterns: type Foo is non-empty
14-
--> $DIR/always-inhabited-union-ref.rs:24:11
14+
--> $DIR/always-inhabited-union-ref.rs:27:11
1515
|
1616
LL | match uninhab_union() {
1717
| ^^^^^^^^^^^^^^^
1818
|
1919
help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
20-
--> $DIR/always-inhabited-union-ref.rs:24:11
20+
--> $DIR/always-inhabited-union-ref.rs:27:11
2121
|
2222
LL | match uninhab_union() {
2323
| ^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)