Skip to content

Commit 2c6bc18

Browse files
committed
Feature gate &Void's uninhabitedness.
References to empty types are only considered empty if feature(never_type) is enabled.
1 parent be1daa4 commit 2c6bc18

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/librustc/ty/inhabitedness/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,13 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
190190
ty.uninhabited_from(visited, tcx)
191191
}
192192
}
193-
TyRef(_, ref tm) => tm.ty.uninhabited_from(visited, tcx),
193+
TyRef(_, ref tm) => {
194+
if tcx.sess.features.borrow().never_type {
195+
tm.ty.uninhabited_from(visited, tcx)
196+
} else {
197+
DefIdForest::empty()
198+
}
199+
}
194200

195201
_ => DefIdForest::empty(),
196202
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum Void {}
12+
13+
fn main() {
14+
let x: Result<u32, &'static Void> = Ok(23);
15+
let _ = match x { //~ ERROR non-exhaustive
16+
Ok(n) => n,
17+
};
18+
}
19+

src/test/run-pass/empty-types-in-patterns.rs

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ fn main() {
5555
Err(e) => match e {},
5656
};
5757

58+
let x: Result<u32, &!> = Ok(123);
59+
match x {
60+
Ok(y) => y,
61+
};
62+
5863
bar(&[]);
5964
}
6065

0 commit comments

Comments
 (0)