Skip to content

Commit

Permalink
Feature gate &Void's uninhabitedness.
Browse files Browse the repository at this point in the history
References to empty types are only considered empty if feature(never_type) is
enabled.
  • Loading branch information
canndrew committed Jan 18, 2017
1 parent be1daa4 commit 2c6bc18
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/librustc/ty/inhabitedness/mod.rs
Expand Up @@ -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(),
}
Expand Down
19 changes: 19 additions & 0 deletions 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

enum Void {}

fn main() {
let x: Result<u32, &'static Void> = Ok(23);
let _ = match x { //~ ERROR non-exhaustive
Ok(n) => n,
};
}

5 changes: 5 additions & 0 deletions src/test/run-pass/empty-types-in-patterns.rs
Expand Up @@ -55,6 +55,11 @@ fn main() {
Err(e) => match e {},
};

let x: Result<u32, &!> = Ok(123);
match x {
Ok(y) => y,
};

bar(&[]);
}

0 comments on commit 2c6bc18

Please sign in to comment.