Skip to content

Commit 839cd04

Browse files
committed
Add only-windows versions of the coerce-issue-49593-box-never test.
1 parent 9d448e8 commit 839cd04

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0277]: the trait bound `(): std::error::Error` is not satisfied
2+
--> $DIR/coerce-issue-49593-box-never.rs:18:53
3+
|
4+
LL | /* *mut $0 is coerced to Box<dyn Error> here */ Box::<_ /* ! */>::new(x)
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
6+
|
7+
= help: the following other types implement trait `std::error::Error`:
8+
!
9+
&'a T
10+
AccessError
11+
AddrParseError
12+
Arc<T>
13+
BorrowError
14+
BorrowMutError
15+
Box<T>
16+
and 45 others
17+
= note: required for the cast to the object type `dyn std::error::Error`
18+
19+
error[E0277]: the trait bound `(): std::error::Error` is not satisfied
20+
--> $DIR/coerce-issue-49593-box-never.rs:23:49
21+
|
22+
LL | /* *mut $0 is coerced to *mut Error here */ raw_ptr_box::<_ /* ! */>(x)
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
24+
|
25+
= help: the following other types implement trait `std::error::Error`:
26+
!
27+
&'a T
28+
AccessError
29+
AddrParseError
30+
Arc<T>
31+
BorrowError
32+
BorrowMutError
33+
Box<T>
34+
and 45 others
35+
= note: required for the cast to the object type `(dyn std::error::Error + 'static)`
36+
37+
error: aborting due to 2 previous errors
38+
39+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// revisions: nofallback fallback
2+
// only-windows - the number of `Error` impls is platform-dependent
3+
//[fallback] check-pass
4+
//[nofallback] check-fail
5+
6+
#![feature(never_type)]
7+
#![cfg_attr(fallback, feature(never_type_fallback))]
8+
#![allow(unreachable_code)]
9+
10+
use std::error::Error;
11+
use std::mem;
12+
13+
fn raw_ptr_box<T>(t: T) -> *mut T {
14+
panic!()
15+
}
16+
17+
fn foo(x: !) -> Box<dyn Error> {
18+
/* *mut $0 is coerced to Box<dyn Error> here */ Box::<_ /* ! */>::new(x)
19+
//[nofallback]~^ ERROR trait bound `(): std::error::Error` is not satisfied
20+
}
21+
22+
fn foo_raw_ptr(x: !) -> *mut dyn Error {
23+
/* *mut $0 is coerced to *mut Error here */ raw_ptr_box::<_ /* ! */>(x)
24+
//[nofallback]~^ ERROR trait bound `(): std::error::Error` is not satisfied
25+
}
26+
27+
fn no_coercion(d: *mut dyn Error) -> *mut dyn Error {
28+
/* an unsize coercion won't compile here, and it is indeed not used
29+
because there is nothing requiring the _ to be Sized */
30+
d as *mut _
31+
}
32+
33+
trait Xyz {}
34+
struct S;
35+
struct T;
36+
impl Xyz for S {}
37+
impl Xyz for T {}
38+
39+
fn foo_no_never() {
40+
let mut x /* : Option<S> */ = None;
41+
let mut first_iter = false;
42+
loop {
43+
if !first_iter {
44+
let y: Box<dyn Xyz>
45+
= /* Box<$0> is coerced to Box<Xyz> here */ Box::new(x.unwrap());
46+
}
47+
48+
x = Some(S);
49+
first_iter = true;
50+
}
51+
52+
let mut y : Option<S> = None;
53+
// assert types are equal
54+
mem::swap(&mut x, &mut y);
55+
}
56+
57+
fn main() {
58+
}

0 commit comments

Comments
 (0)