Skip to content

Commit 0caefea

Browse files
committed
add tests for unsizing coercions (both ICE)
1 parent f524236 commit 0caefea

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

tests/ui/dst/dst-object-from-unsized-type.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// Test that we cannot create objects from unsized types.
2+
//@ revisions: current next
3+
//@ ignore-compare-mode-next-solver (explicit revisions)
4+
//@[next] compile-flags: -Znext-solver
25

36
trait Foo { fn foo(&self) {} }
47
impl Foo for str {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ check-pass
2+
//@ revisions: current next
3+
//@ ignore-compare-mode-next-solver (explicit revisions)
4+
//@[next] compile-flags: -Znext-solver
5+
6+
trait Super<T> {}
7+
trait Trait<T>: Super<T> + for<'hr> Super<&'hr ()> {}
8+
9+
fn foo<'a>(x: Box<dyn Trait<&'a ()>>) -> Box<dyn Super<&'a ()>> {
10+
x
11+
}
12+
13+
fn main() {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@ compile-flags: -Znext-solver
2+
trait Super<'a> {}
3+
trait Trait<'a>: Super<'a> + for<'hr> Super<'hr> {}
4+
5+
fn foo<'a>(x: Box<dyn Trait<'a>>) -> Box<dyn Super<'a>> {
6+
x
7+
//~^ ERROR type annotations needed: cannot satisfy `dyn Trait<'_>: Unsize<dyn Super<'_>>
8+
}
9+
10+
fn main() {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//@ compile-flags: -Znext-solver
2+
#![recursion_limit = "8"]
3+
4+
fn main() {
5+
let _: Box<dyn Send> = Box::new(&&&&&&&1);
6+
//~^ ERROR overflow evaluating the requirement `Box<&&&&&&&i32>: CoerceUnsized<Box<dyn Send>>
7+
}

0 commit comments

Comments
 (0)