]> git.lizzy.rs Git - rust.git/blob - src/test/ui/coercion/coerce-issue-49593-box-never.rs
Rollup merge of #93813 - xldenis:public-mir-passes, r=wesleywiser
[rust.git] / src / test / ui / coercion / coerce-issue-49593-box-never.rs
1 // revisions: nofallback fallback
2 //[fallback] check-pass
3 //[nofallback] check-fail
4
5 #![feature(never_type)]
6 #![cfg_attr(fallback, feature(never_type_fallback))]
7 #![allow(unreachable_code)]
8
9 use std::error::Error;
10 use std::mem;
11
12 fn raw_ptr_box<T>(t: T) -> *mut T {
13     panic!()
14 }
15
16 fn foo(x: !) -> Box<dyn Error> {
17     /* *mut $0 is coerced to Box<dyn Error> here */ Box::<_ /* ! */>::new(x)
18     //[nofallback]~^ ERROR trait bound `(): std::error::Error` is not satisfied
19 }
20
21 fn foo_raw_ptr(x: !) -> *mut dyn Error {
22     /* *mut $0 is coerced to *mut Error here */ raw_ptr_box::<_ /* ! */>(x)
23     //[nofallback]~^ ERROR trait bound `(): std::error::Error` is not satisfied
24 }
25
26 fn no_coercion(d: *mut dyn Error) -> *mut dyn Error {
27     /* an unsize coercion won't compile here, and it is indeed not used
28        because there is nothing requiring the _ to be Sized */
29     d as *mut _
30 }
31
32 trait Xyz {}
33 struct S;
34 struct T;
35 impl Xyz for S {}
36 impl Xyz for T {}
37
38 fn foo_no_never() {
39     let mut x /* : Option<S> */ = None;
40     let mut first_iter = false;
41     loop {
42         if !first_iter {
43             let y: Box<dyn Xyz>
44                 = /* Box<$0> is coerced to Box<Xyz> here */ Box::new(x.unwrap());
45         }
46
47         x = Some(S);
48         first_iter = true;
49     }
50
51     let mut y : Option<S> = None;
52     // assert types are equal
53     mem::swap(&mut x, &mut y);
54 }
55
56 fn main() {
57 }