Skip to content

Commit 87482ee

Browse files
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.
2 parents c593ff4 + 2c6bc18 commit 87482ee

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/librustc/ty/inhabitedness/mod.rs

Lines changed: 7 additions & 1 deletion
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
}
Lines changed: 19 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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)