Skip to content

Commit ea3c339

Browse files
committed
More tests
1 parent 4ffecb9 commit ea3c339

6 files changed

+140
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0271]: type mismatch resolving `impl Trait + ?Sized <: dyn Send`
2+
--> $DIR/unsized_coercion3.rs:13:17
3+
|
4+
LL | let x = hello();
5+
| ^^^^^^^ types differ
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0271`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: cannot check whether the hidden type of opaque type satisfies auto traits
2+
--> $DIR/unsized_coercion3.rs:15:32
3+
|
4+
LL | let y: Box<dyn Send> = x;
5+
| ^
6+
|
7+
= note: fetching the hidden types of an opaque inside of the defining scope is not supported. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule
8+
note: opaque type is declared here
9+
--> $DIR/unsized_coercion3.rs:11:19
10+
|
11+
LL | fn hello() -> Box<impl Trait + ?Sized> {
12+
| ^^^^^^^^^^^^^^^^^^^
13+
= note: required for the cast from `Box<impl Trait + ?Sized>` to `Box<dyn Send>`
14+
15+
error[E0277]: the size for values of type `impl Trait + ?Sized` cannot be known at compilation time
16+
--> $DIR/unsized_coercion3.rs:15:32
17+
|
18+
LL | let y: Box<dyn Send> = x;
19+
| ^ doesn't have a size known at compile-time
20+
|
21+
= help: the trait `Sized` is not implemented for `impl Trait + ?Sized`
22+
= note: required for the cast from `Box<impl Trait + ?Sized>` to `Box<dyn Send>`
23+
24+
error: aborting due to 2 previous errors
25+
26+
For more information about this error, try `rustc --explain E0277`.
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//! This test checks that opaque types get unsized instead of
2+
//! constraining their hidden type to a trait object.
3+
4+
//@ revisions: next old
5+
//@[next] compile-flags: -Znext-solver
6+
7+
trait Trait {}
8+
9+
impl Trait for u32 {}
10+
11+
fn hello() -> Box<impl Trait + ?Sized> {
12+
if true {
13+
let x = hello();
14+
//[next]~^ ERROR: type mismatch resolving `impl Trait + ?Sized <: dyn Send`
15+
let y: Box<dyn Send> = x;
16+
//[old]~^ ERROR: the size for values of type `impl Trait + ?Sized` cannot be know
17+
//[old]~| ERROR: cannot check whether the hidden type of opaque type satisfies auto traits
18+
}
19+
Box::new(1u32)
20+
}
21+
22+
fn main() {}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! This test checks that opaque types get unsized instead of
2+
//! constraining their hidden type to a trait object.
3+
4+
//@ revisions: next old
5+
//@[next] compile-flags: -Znext-solver
6+
//@check-pass
7+
8+
trait Trait {}
9+
10+
impl Trait for u32 {}
11+
12+
fn hello() -> Box<impl Trait + ?Sized> {
13+
if true {
14+
let x = hello() as Box<u32>;
15+
let y: Box<dyn Send> = x;
16+
}
17+
Box::new(1u32)
18+
}
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/unsized_coercion5.rs:17:32
3+
|
4+
LL | let y: Box<dyn Send> = x as Box<dyn Trait + Send>;
5+
| ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait `Send`, found trait `Trait + Send`
6+
| |
7+
| expected due to this
8+
|
9+
= note: expected struct `Box<dyn Send>`
10+
found struct `Box<dyn Trait + Send>`
11+
12+
error: cannot check whether the hidden type of opaque type satisfies auto traits
13+
--> $DIR/unsized_coercion5.rs:17:32
14+
|
15+
LL | let y: Box<dyn Send> = x as Box<dyn Trait + Send>;
16+
| ^
17+
|
18+
= note: fetching the hidden types of an opaque inside of the defining scope is not supported. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule
19+
note: opaque type is declared here
20+
--> $DIR/unsized_coercion5.rs:14:19
21+
|
22+
LL | fn hello() -> Box<impl Trait + ?Sized> {
23+
| ^^^^^^^^^^^^^^^^^^^
24+
= note: required for the cast from `Box<impl Trait + ?Sized>` to `Box<dyn Trait + Send>`
25+
26+
error[E0277]: the size for values of type `impl Trait + ?Sized` cannot be known at compilation time
27+
--> $DIR/unsized_coercion5.rs:17:32
28+
|
29+
LL | let y: Box<dyn Send> = x as Box<dyn Trait + Send>;
30+
| ^ doesn't have a size known at compile-time
31+
|
32+
= help: the trait `Sized` is not implemented for `impl Trait + ?Sized`
33+
= note: required for the cast from `Box<impl Trait + ?Sized>` to `Box<dyn Trait + Send>`
34+
35+
error: aborting due to 3 previous errors
36+
37+
Some errors have detailed explanations: E0277, E0308.
38+
For more information about an error, try `rustc --explain E0277`.
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//! This test checks that opaque types get unsized instead of
2+
//! constraining their hidden type to a trait object.
3+
4+
//@ revisions: next old
5+
//@[next] compile-flags: -Znext-solver
6+
//@[next] check-pass
7+
8+
#![feature(trait_upcasting)]
9+
10+
trait Trait {}
11+
12+
impl Trait for u32 {}
13+
14+
fn hello() -> Box<impl Trait + ?Sized> {
15+
if true {
16+
let x = hello();
17+
let y: Box<dyn Send> = x as Box<dyn Trait + Send>;
18+
//[old]~^ ERROR: the size for values of type `impl Trait + ?Sized` cannot be know
19+
//[old]~| ERROR: mismatched types
20+
//[old]~| ERROR: cannot check whether the hidden type of opaque type satisfies auto traits
21+
}
22+
Box::new(1u32)
23+
}
24+
25+
fn main() {}

0 commit comments

Comments
 (0)