Skip to content

Commit ab97868

Browse files
committed
add tests for unsizing coercions (both ICE)
1 parent ebe145e commit ab97868

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ check-pass
2+
//@ revisions: current next
3+
//@ ignore-compare-mode-next-solver (explicit revisions)
4+
//@[next] compile-flags: -Znext-solver
5+
// Test from trait-system-refactor-initiative#241:
6+
// Used to ICE in mir typeck because of ambiguity in the new solver.
7+
// The wrong (first) trait bound was selected.
8+
// This is fixed with new logic for unsizing coercions that's independent from that of the old solver, which this test verifies.
9+
10+
trait Super<T> {}
11+
trait Trait<T>: Super<T> + for<'hr> Super<&'hr ()> {}
12+
13+
fn foo<'a>(x: Box<dyn Trait<&'a ()>>) -> Box<dyn Super<&'a ()>> {
14+
x
15+
}
16+
17+
fn main() {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ check-pass
2+
//@ revisions: current next
3+
//@ ignore-compare-mode-next-solver (explicit revisions)
4+
//@[next] compile-flags: -Znext-solver
5+
// Test from trait-system-refactor-initiative#241:
6+
// Used to ICE in mir typeck because of ambiguity in the new solver.
7+
// The wrong (first) trait bound was selected.
8+
// This is fixed with new logic for unsizing coercions that's independent from that of the old solver, which this test verifies.
9+
10+
trait Super<'a> {}
11+
trait Trait<'a>: Super<'a> + for<'hr> Super<'hr> {}
12+
13+
fn foo<'a>(x: Box<dyn Trait<'a>>) -> Box<dyn Super<'a>> {
14+
x
15+
//~^ ERROR type annotations needed: cannot satisfy `dyn Trait<'_>: Unsize<dyn Super<'_>>
16+
}
17+
18+
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)