]> git.lizzy.rs Git - rust.git/blob - src/test/ui/coercion/coerce-issue-49593-box-never.rs
Rollup merge of #56914 - glaubitz:ignore-tests, r=alexcrichton
[rust.git] / src / test / ui / coercion / coerce-issue-49593-box-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 #![feature(never_type)]
14 #![allow(unreachable_code)]
15
16 use std::error::Error;
17 use std::mem;
18
19 fn raw_ptr_box<T>(t: T) -> *mut T {
20     panic!()
21 }
22
23 fn foo(x: !) -> Box<dyn Error> {
24     /* *mut $0 is coerced to Box<dyn Error> here */ Box::<_ /* ! */>::new(x)
25 }
26
27 fn foo_raw_ptr(x: !) -> *mut dyn Error {
28     /* *mut $0 is coerced to *mut Error here */ raw_ptr_box::<_ /* ! */>(x)
29 }
30
31 fn no_coercion(d: *mut dyn Error) -> *mut dyn Error {
32     /* an unsize coercion won't compile here, and it is indeed not used
33        because there is nothing requiring the _ to be Sized */
34     d as *mut _
35 }
36
37 trait Xyz {}
38 struct S;
39 struct T;
40 impl Xyz for S {}
41 impl Xyz for T {}
42
43 fn foo_no_never() {
44     let mut x /* : Option<S> */ = None;
45     let mut first_iter = false;
46     loop {
47         if !first_iter {
48             let y: Box<dyn Xyz>
49                 = /* Box<$0> is coerced to Box<Xyz> here */ Box::new(x.unwrap());
50         }
51
52         x = Some(S);
53         first_iter = true;
54     }
55
56     let mut y : Option<S> = None;
57     // assert types are equal
58     mem::swap(&mut x, &mut y);
59 }
60
61 fn main() {
62 }