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.
This commit is contained in:
Noah Lev 2024-07-31 20:33:48 -07:00
parent e57f3090ae
commit 18906754cc
2 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,10 @@
struct Foo {
nested: &'static Bar<dyn std::fmt::Debug>,
//~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
}
struct Bar<T>(T);
fn main() {
let x = Foo { nested: &Bar(4) };
}

View File

@ -0,0 +1,23 @@
error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time
--> $DIR/field-implied-unsizing-wfcheck.rs:2:13
|
LL | nested: &'static Bar<dyn std::fmt::Debug>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `(dyn Debug + 'static)`
note: required by an implicit `Sized` bound in `Bar`
--> $DIR/field-implied-unsizing-wfcheck.rs:6:12
|
LL | struct Bar<T>(T);
| ^ required by the implicit `Sized` requirement on this type parameter in `Bar`
help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`
--> $DIR/field-implied-unsizing-wfcheck.rs:6:12
|
LL | struct Bar<T>(T);
| ^ - ...if indirection were used here: `Box<T>`
| |
| this could be changed to `T: ?Sized`...
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.