]> git.lizzy.rs Git - rust.git/blob - src/test/ui/never_transmute_never.rs
Auto merge of #54720 - davidtwco:issue-51191, r=nikomatsakis
[rust.git] / src / test / ui / never_transmute_never.rs
1 // Copyright 2018 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 // compile-pass
12
13 #![crate_type="lib"]
14
15 #![feature(never_type)]
16 #![allow(dead_code)]
17 #![allow(unreachable_code)]
18 #![allow(unused_variables)]
19
20 struct Foo;
21
22 pub fn f(x: !) -> ! {
23     x
24 }
25
26 pub fn ub() {
27     // This is completely undefined behaviour,
28     // but we still want to make sure it compiles.
29     let x: ! = unsafe {
30         std::mem::transmute::<Foo, !>(Foo)
31     };
32     f(x)
33 }