Skip to content

Commit 1890675

Browse files
committed
Add test for WF check of implied unsizing in struct fields
Note that the test output is currently *incorrect*. We should be emitting an error at the use site too, not just at the definition. This is partly for UI reasons, but mainly to fix a related ICE where a const generic body is not tainted with an error since no usage error is reported.
1 parent e57f309 commit 1890675

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
struct Foo {
2+
nested: &'static Bar<dyn std::fmt::Debug>,
3+
//~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
4+
}
5+
6+
struct Bar<T>(T);
7+
8+
fn main() {
9+
let x = Foo { nested: &Bar(4) };
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
2+
--> $DIR/field-implied-unsizing-wfcheck.rs:2:13
3+
|
4+
LL | nested: &'static Bar<dyn std::fmt::Debug>,
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
6+
|
7+
= help: the trait `Sized` is not implemented for `(dyn Debug + 'static)`
8+
note: required by an implicit `Sized` bound in `Bar`
9+
--> $DIR/field-implied-unsizing-wfcheck.rs:6:12
10+
|
11+
LL | struct Bar<T>(T);
12+
| ^ required by the implicit `Sized` requirement on this type parameter in `Bar`
13+
help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`
14+
--> $DIR/field-implied-unsizing-wfcheck.rs:6:12
15+
|
16+
LL | struct Bar<T>(T);
17+
| ^ - ...if indirection were used here: `Box<T>`
18+
| |
19+
| this could be changed to `T: ?Sized`...
20+
21+
error: aborting due to 1 previous error
22+
23+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)