From 2f4603b7158025119f45d905d665291b67d3e43d Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Mon, 5 Aug 2024 17:56:50 -0700 Subject: [PATCH] Test more cases of WF-checking for fields --- .../structs/field-implied-unsizing-wfcheck.rs | 25 +++- .../field-implied-unsizing-wfcheck.stderr | 136 ++++++++++++++++-- 2 files changed, 151 insertions(+), 10 deletions(-) diff --git a/tests/ui/structs/field-implied-unsizing-wfcheck.rs b/tests/ui/structs/field-implied-unsizing-wfcheck.rs index 981ff138de3..a46c9b5a68b 100644 --- a/tests/ui/structs/field-implied-unsizing-wfcheck.rs +++ b/tests/ui/structs/field-implied-unsizing-wfcheck.rs @@ -1,11 +1,32 @@ -struct Foo { +struct FooStruct { nested: &'static Bar, //~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time } +struct FooTuple(&'static Bar); +//~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time + +enum FooEnum1 { + Struct { nested: &'static Bar }, + //~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time +} + +enum FooEnum2 { + Tuple(&'static Bar), + //~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time +} + struct Bar(T); fn main() { - let x = Foo { nested: &Bar(4) }; + // Ensure there's an error at the construction site, for error tainting purposes. + + FooStruct { nested: &Bar(4) }; + //~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time + FooTuple(&Bar(4)); + //~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time + FooEnum1::Struct { nested: &Bar(4) }; + //~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time + FooEnum2::Tuple(&Bar(4)); //~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time } diff --git a/tests/ui/structs/field-implied-unsizing-wfcheck.stderr b/tests/ui/structs/field-implied-unsizing-wfcheck.stderr index 79198c86141..47d486ffa33 100644 --- a/tests/ui/structs/field-implied-unsizing-wfcheck.stderr +++ b/tests/ui/structs/field-implied-unsizing-wfcheck.stderr @@ -6,12 +6,12 @@ LL | nested: &'static Bar, | = 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 + --> $DIR/field-implied-unsizing-wfcheck.rs:19:12 | LL | struct Bar(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` - --> $DIR/field-implied-unsizing-wfcheck.rs:6:12 + --> $DIR/field-implied-unsizing-wfcheck.rs:19:12 | LL | struct Bar(T); | ^ - ...if indirection were used here: `Box` @@ -19,25 +19,145 @@ LL | struct Bar(T); | this could be changed to `T: ?Sized`... error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time - --> $DIR/field-implied-unsizing-wfcheck.rs:9:27 + --> $DIR/field-implied-unsizing-wfcheck.rs:6:17 | -LL | let x = Foo { nested: &Bar(4) }; - | ^^^^^^^ doesn't have a size known at compile-time +LL | struct FooTuple(&'static Bar); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 + --> $DIR/field-implied-unsizing-wfcheck.rs:19:12 | LL | struct Bar(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` - --> $DIR/field-implied-unsizing-wfcheck.rs:6:12 + --> $DIR/field-implied-unsizing-wfcheck.rs:19:12 | LL | struct Bar(T); | ^ - ...if indirection were used here: `Box` | | | this could be changed to `T: ?Sized`... -error: aborting due to 2 previous errors +error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time + --> $DIR/field-implied-unsizing-wfcheck.rs:10:22 + | +LL | Struct { nested: &'static Bar }, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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:19:12 + | +LL | struct Bar(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` + --> $DIR/field-implied-unsizing-wfcheck.rs:19:12 + | +LL | struct Bar(T); + | ^ - ...if indirection were used here: `Box` + | | + | this could be changed to `T: ?Sized`... + +error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time + --> $DIR/field-implied-unsizing-wfcheck.rs:15:11 + | +LL | Tuple(&'static Bar), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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:19:12 + | +LL | struct Bar(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` + --> $DIR/field-implied-unsizing-wfcheck.rs:19:12 + | +LL | struct Bar(T); + | ^ - ...if indirection were used here: `Box` + | | + | this could be changed to `T: ?Sized`... + +error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time + --> $DIR/field-implied-unsizing-wfcheck.rs:24:25 + | +LL | FooStruct { nested: &Bar(4) }; + | ^^^^^^^ 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:19:12 + | +LL | struct Bar(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` + --> $DIR/field-implied-unsizing-wfcheck.rs:19:12 + | +LL | struct Bar(T); + | ^ - ...if indirection were used here: `Box` + | | + | this could be changed to `T: ?Sized`... + +error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time + --> $DIR/field-implied-unsizing-wfcheck.rs:26:14 + | +LL | FooTuple(&Bar(4)); + | ^^^^^^^ 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:19:12 + | +LL | struct Bar(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` + --> $DIR/field-implied-unsizing-wfcheck.rs:19:12 + | +LL | struct Bar(T); + | ^ - ...if indirection were used here: `Box` + | | + | this could be changed to `T: ?Sized`... + +error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time + --> $DIR/field-implied-unsizing-wfcheck.rs:28:32 + | +LL | FooEnum1::Struct { nested: &Bar(4) }; + | ^^^^^^^ 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:19:12 + | +LL | struct Bar(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` + --> $DIR/field-implied-unsizing-wfcheck.rs:19:12 + | +LL | struct Bar(T); + | ^ - ...if indirection were used here: `Box` + | | + | this could be changed to `T: ?Sized`... + +error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time + --> $DIR/field-implied-unsizing-wfcheck.rs:30:21 + | +LL | FooEnum2::Tuple(&Bar(4)); + | ^^^^^^^ 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:19:12 + | +LL | struct Bar(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` + --> $DIR/field-implied-unsizing-wfcheck.rs:19:12 + | +LL | struct Bar(T); + | ^ - ...if indirection were used here: `Box` + | | + | this could be changed to `T: ?Sized`... + +error: aborting due to 8 previous errors For more information about this error, try `rustc --explain E0277`.