]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/uninhabited-patterns.rs
New upstream version 1.24.1+dfsg1
[rustc.git] / src / test / compile-fail / uninhabited-patterns.rs
1 // Copyright 2012 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 #![feature(box_patterns)]
12 #![feature(slice_patterns)]
13 #![feature(box_syntax)]
14 #![feature(never_type)]
15 #![deny(unreachable_patterns)]
16
17 mod foo {
18 pub struct SecretlyEmpty {
19 _priv: !,
20 }
21 }
22
23 struct NotSoSecretlyEmpty {
24 _priv: !,
25 }
26
27 fn foo() -> Option<NotSoSecretlyEmpty> {
28 None
29 }
30
31 fn main() {
32 let x: &[!] = &[];
33
34 match x {
35 &[] => (),
36 &[..] => (), //~ ERROR unreachable pattern
37 };
38
39 let x: Result<Box<NotSoSecretlyEmpty>, &[Result<!, !>]> = Err(&[]);
40 match x {
41 Ok(box _) => (), //~ ERROR unreachable pattern
42 Err(&[]) => (),
43 Err(&[..]) => (), //~ ERROR unreachable pattern
44 }
45
46 let x: Result<foo::SecretlyEmpty, Result<NotSoSecretlyEmpty, u32>> = Err(Err(123));
47 match x {
48 Ok(_y) => (),
49 Err(Err(_y)) => (),
50 Err(Ok(_y)) => (), //~ ERROR unreachable pattern
51 }
52
53 while let Some(_y) = foo() {
54 //~^ ERROR unreachable pattern
55 }
56 }
57