diff options
| -rw-r--r-- | tests/ui/structs/field-implied-unsizing-wfcheck.rs | 10 | ||||
| -rw-r--r-- | tests/ui/structs/field-implied-unsizing-wfcheck.stderr | 23 |
2 files changed, 33 insertions, 0 deletions
diff --git a/tests/ui/structs/field-implied-unsizing-wfcheck.rs b/tests/ui/structs/field-implied-unsizing-wfcheck.rs new file mode 100644 index 00000000000..24da4b5e89d --- /dev/null +++ b/tests/ui/structs/field-implied-unsizing-wfcheck.rs @@ -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) }; +} diff --git a/tests/ui/structs/field-implied-unsizing-wfcheck.stderr b/tests/ui/structs/field-implied-unsizing-wfcheck.stderr new file mode 100644 index 00000000000..c47918c7d16 --- /dev/null +++ b/tests/ui/structs/field-implied-unsizing-wfcheck.stderr @@ -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`. |
