Skip to content

Commit 4531f5d

Browse files
committed
prove both newly added tests are fixed by the changes
1 parent 7d23487 commit 4531f5d

8 files changed

+104
-7
lines changed

tests/ui/dst/dst-object-from-unsized-type.stderr renamed to tests/ui/dst/dst-object-from-unsized-type.current.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: the size for values of type `T` cannot be known at compilation time
2-
--> $DIR/dst-object-from-unsized-type.rs:8:23
2+
--> $DIR/dst-object-from-unsized-type.rs:11:23
33
|
44
LL | fn test1<T: ?Sized + Foo>(t: &T) {
55
| - this type parameter needs to be `Sized`
@@ -14,7 +14,7 @@ LL + fn test1<T: Foo>(t: &T) {
1414
|
1515

1616
error[E0277]: the size for values of type `T` cannot be known at compilation time
17-
--> $DIR/dst-object-from-unsized-type.rs:13:23
17+
--> $DIR/dst-object-from-unsized-type.rs:16:23
1818
|
1919
LL | fn test2<T: ?Sized + Foo>(t: &T) {
2020
| - this type parameter needs to be `Sized`
@@ -29,7 +29,7 @@ LL + fn test2<T: Foo>(t: &T) {
2929
|
3030

3131
error[E0277]: the size for values of type `str` cannot be known at compilation time
32-
--> $DIR/dst-object-from-unsized-type.rs:18:28
32+
--> $DIR/dst-object-from-unsized-type.rs:21:28
3333
|
3434
LL | let _: &[&dyn Foo] = &["hi"];
3535
| ^^^^ doesn't have a size known at compile-time
@@ -38,7 +38,7 @@ LL | let _: &[&dyn Foo] = &["hi"];
3838
= note: required for the cast from `&'static str` to `&dyn Foo`
3939

4040
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
41-
--> $DIR/dst-object-from-unsized-type.rs:23:23
41+
--> $DIR/dst-object-from-unsized-type.rs:26:23
4242
|
4343
LL | let _: &dyn Foo = x as &dyn Foo;
4444
| ^ doesn't have a size known at compile-time
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/dst-object-from-unsized-type.rs:11:23
3+
|
4+
LL | fn test1<T: ?Sized + Foo>(t: &T) {
5+
| - found this type parameter
6+
LL | let u: &dyn Foo = t;
7+
| -------- ^ expected `&dyn Foo`, found `&T`
8+
| |
9+
| expected due to this
10+
|
11+
= note: expected reference `&dyn Foo`
12+
found reference `&T`
13+
= help: type parameters must be constrained to match other types
14+
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
15+
16+
error[E0605]: non-primitive cast: `&T` as `&dyn Foo`
17+
--> $DIR/dst-object-from-unsized-type.rs:16:23
18+
|
19+
LL | let v: &dyn Foo = t as &dyn Foo;
20+
| ^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
21+
22+
error[E0308]: mismatched types
23+
--> $DIR/dst-object-from-unsized-type.rs:21:28
24+
|
25+
LL | let _: &[&dyn Foo] = &["hi"];
26+
| ^^^^ expected `&dyn Foo`, found `&str`
27+
|
28+
= note: expected reference `&dyn Foo`
29+
found reference `&'static str`
30+
= help: `str` implements `Foo` so you could box the found value and coerce it to the trait object `Box<dyn Foo>`, you will have to change the expected type as well
31+
32+
error[E0605]: non-primitive cast: `&[u8]` as `&dyn Foo`
33+
--> $DIR/dst-object-from-unsized-type.rs:26:23
34+
|
35+
LL | let _: &dyn Foo = x as &dyn Foo;
36+
| ^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
37+
38+
error: aborting due to 4 previous errors
39+
40+
Some errors have detailed explanations: E0308, E0605.
41+
For more information about an error, try `rustc --explain E0308`.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0283]: type annotations needed: cannot satisfy `dyn Trait<&()>: Unsize<dyn Super<&()>>`
2+
--> $DIR/unsize-goal-mismatch-2.rs:14:5
3+
|
4+
LL | x
5+
| ^
6+
|
7+
= note: cannot satisfy `dyn Trait<&()>: Unsize<dyn Super<&()>>`
8+
= note: required for `Box<dyn Trait<&()>>` to implement `CoerceUnsized<Box<dyn Super<&()>>>`
9+
= note: required for the cast from `Box<(dyn Trait<&'a ()> + 'static)>` to `Box<(dyn Super<&'a ()> + 'static)>`
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0283`.

tests/ui/traits/next-solver/unsize-goal-mismatch-2.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
//@ check-pass
21
//@ revisions: current next
32
//@ ignore-compare-mode-next-solver (explicit revisions)
43
//@[next] compile-flags: -Znext-solver
4+
//@[current] check-pass
55
// Test from trait-system-refactor-initiative#241:
66
// Used to ICE in mir typeck because of ambiguity in the new solver.
77
// The wrong (first) trait bound was selected.
@@ -12,6 +12,7 @@ trait Trait<T>: Super<T> + for<'hr> Super<&'hr ()> {}
1212

1313
fn foo<'a>(x: Box<dyn Trait<&'a ()>>) -> Box<dyn Super<&'a ()>> {
1414
x
15+
//[next]~^ ERROR type annotations needed: cannot satisfy `dyn Trait<&()>: Unsize<dyn Super<&()>>`
1516
}
1617

1718
fn main() {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0283]: type annotations needed: cannot satisfy `Self: Super<'a>`
2+
--> $DIR/unsize-goal-mismatch.rs:10:18
3+
|
4+
LL | trait Trait<'a>: Super<'a> + for<'hr> Super<'hr> {}
5+
| ^^^^^^^^^
6+
|
7+
note: multiple `impl`s or `where` clauses satisfying `Self: Super<'a>` found
8+
--> $DIR/unsize-goal-mismatch.rs:9:1
9+
|
10+
LL | trait Super<'a> {}
11+
| ^^^^^^^^^^^^^^^
12+
LL | trait Trait<'a>: Super<'a> + for<'hr> Super<'hr> {}
13+
| ^^^^^^^^^^^^^^^^^^^
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0283`.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0283]: type annotations needed: cannot satisfy `dyn Trait<'_>: Unsize<dyn Super<'_>>`
2+
--> $DIR/unsize-goal-mismatch.rs:14:5
3+
|
4+
LL | x
5+
| ^
6+
|
7+
= note: cannot satisfy `dyn Trait<'_>: Unsize<dyn Super<'_>>`
8+
= note: required for `Box<dyn Trait<'_>>` to implement `CoerceUnsized<Box<dyn Super<'_>>>`
9+
= note: required for the cast from `Box<(dyn Trait<'a> + 'static)>` to `Box<(dyn Super<'a> + 'static)>`
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0283`.

tests/ui/traits/next-solver/unsize-goal-mismatch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@ check-pass
21
//@ revisions: current next
32
//@ ignore-compare-mode-next-solver (explicit revisions)
43
//@[next] compile-flags: -Znext-solver
@@ -9,10 +8,11 @@
98

109
trait Super<'a> {}
1110
trait Trait<'a>: Super<'a> + for<'hr> Super<'hr> {}
11+
//[current]~^ ERROR type annotations needed: cannot satisfy `Self: Super<'a>`
1212

1313
fn foo<'a>(x: Box<dyn Trait<'a>>) -> Box<dyn Super<'a>> {
1414
x
15-
//~^ ERROR type annotations needed: cannot satisfy `dyn Trait<'_>: Unsize<dyn Super<'_>>
15+
//[next]~^ ERROR type annotations needed: cannot satisfy `dyn Trait<'_>: Unsize<dyn Super<'_>>
1616
}
1717

1818
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0275]: overflow evaluating the requirement `Box<&&&&&&&i32>: CoerceUnsized<Box<dyn Send>>`
2+
--> $DIR/unsize-overflow.rs:5:28
3+
|
4+
LL | let _: Box<dyn Send> = Box::new(&&&&&&&1);
5+
| ^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "16"]` attribute to your crate (`unsize_overflow`)
8+
= note: required for the cast from `Box<&&&&&&&i32>` to `Box<dyn Send>`
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0275`.

0 commit comments

Comments
 (0)