rust/tests/ui/coercion/coerce-issue-49593-box-never.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

59 lines
1.4 KiB
Rust
Raw Normal View History

2021-09-17 13:59:50 +00:00
// revisions: nofallback fallback
// ignore-windows - the number of `Error` impls is platform-dependent
2021-09-17 13:59:50 +00:00
//[fallback] check-pass
//[nofallback] check-fail
#![feature(never_type)]
#![cfg_attr(fallback, feature(never_type_fallback))]
#![allow(unreachable_code)]
use std::error::Error;
2018-11-25 21:51:23 +00:00
use std::mem;
fn raw_ptr_box<T>(t: T) -> *mut T {
panic!()
}
2018-11-25 21:51:23 +00:00
fn foo(x: !) -> Box<dyn Error> {
/* *mut $0 is coerced to Box<dyn Error> here */ Box::<_ /* ! */>::new(x)
2021-09-17 13:59:50 +00:00
//[nofallback]~^ ERROR trait bound `(): std::error::Error` is not satisfied
}
2018-11-25 21:51:23 +00:00
fn foo_raw_ptr(x: !) -> *mut dyn Error {
/* *mut $0 is coerced to *mut Error here */ raw_ptr_box::<_ /* ! */>(x)
2021-09-17 13:59:50 +00:00
//[nofallback]~^ ERROR trait bound `(): std::error::Error` is not satisfied
}
2018-11-25 21:51:23 +00:00
fn no_coercion(d: *mut dyn Error) -> *mut dyn Error {
/* an unsize coercion won't compile here, and it is indeed not used
because there is nothing requiring the _ to be Sized */
d as *mut _
}
trait Xyz {}
struct S;
struct T;
impl Xyz for S {}
impl Xyz for T {}
fn foo_no_never() {
2018-11-25 21:51:23 +00:00
let mut x /* : Option<S> */ = None;
let mut first_iter = false;
loop {
if !first_iter {
2018-11-25 21:51:23 +00:00
let y: Box<dyn Xyz>
= /* Box<$0> is coerced to Box<Xyz> here */ Box::new(x.unwrap());
}
x = Some(S);
first_iter = true;
}
2018-11-25 21:51:23 +00:00
let mut y : Option<S> = None;
// assert types are equal
2018-11-26 08:23:42 +00:00
mem::swap(&mut x, &mut y);
}
fn main() {
}