2021-09-17 08:59:50 -05:00
|
|
|
// revisions: nofallback fallback
|
2022-04-19 16:19:50 -05:00
|
|
|
// ignore-windows - the number of `Error` impls is platform-dependent
|
2021-09-17 08:59:50 -05:00
|
|
|
//[fallback] check-pass
|
|
|
|
//[nofallback] check-fail
|
|
|
|
|
|
|
|
#![feature(never_type)]
|
|
|
|
#![cfg_attr(fallback, feature(never_type_fallback))]
|
2018-11-25 08:14:54 -06:00
|
|
|
#![allow(unreachable_code)]
|
|
|
|
|
|
|
|
use std::error::Error;
|
2018-11-25 15:51:23 -06:00
|
|
|
use std::mem;
|
2018-11-25 08:14:54 -06:00
|
|
|
|
|
|
|
fn raw_ptr_box<T>(t: T) -> *mut T {
|
|
|
|
panic!()
|
|
|
|
}
|
|
|
|
|
2018-11-25 15:51:23 -06:00
|
|
|
fn foo(x: !) -> Box<dyn Error> {
|
|
|
|
/* *mut $0 is coerced to Box<dyn Error> here */ Box::<_ /* ! */>::new(x)
|
2021-09-17 08:59:50 -05:00
|
|
|
//[nofallback]~^ ERROR trait bound `(): std::error::Error` is not satisfied
|
2018-11-25 08:14:54 -06:00
|
|
|
}
|
|
|
|
|
2018-11-25 15:51:23 -06:00
|
|
|
fn foo_raw_ptr(x: !) -> *mut dyn Error {
|
2018-11-25 08:14:54 -06:00
|
|
|
/* *mut $0 is coerced to *mut Error here */ raw_ptr_box::<_ /* ! */>(x)
|
2021-09-17 08:59:50 -05:00
|
|
|
//[nofallback]~^ ERROR trait bound `(): std::error::Error` is not satisfied
|
2018-11-25 08:14:54 -06:00
|
|
|
}
|
|
|
|
|
2018-11-25 15:51:23 -06:00
|
|
|
fn no_coercion(d: *mut dyn Error) -> *mut dyn Error {
|
2018-11-25 08:14:54 -06:00
|
|
|
/* 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 15:51:23 -06:00
|
|
|
let mut x /* : Option<S> */ = None;
|
2018-11-25 08:14:54 -06:00
|
|
|
let mut first_iter = false;
|
|
|
|
loop {
|
|
|
|
if !first_iter {
|
2018-11-25 15:51:23 -06:00
|
|
|
let y: Box<dyn Xyz>
|
2018-11-25 08:14:54 -06:00
|
|
|
= /* Box<$0> is coerced to Box<Xyz> here */ Box::new(x.unwrap());
|
|
|
|
}
|
|
|
|
|
|
|
|
x = Some(S);
|
|
|
|
first_iter = true;
|
|
|
|
}
|
2018-11-25 15:51:23 -06:00
|
|
|
|
|
|
|
let mut y : Option<S> = None;
|
|
|
|
// assert types are equal
|
2018-11-26 02:23:42 -06:00
|
|
|
mem::swap(&mut x, &mut y);
|
2018-11-25 08:14:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
}
|