diff options
| -rw-r--r-- | tests/ui/structs/field-implied-unsizing-wfcheck.rs | 25 | ||||
| -rw-r--r-- | tests/ui/structs/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<dyn std::fmt::Debug>, //~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time } +struct FooTuple(&'static Bar<dyn std::fmt::Debug>); +//~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time + +enum FooEnum1 { + Struct { nested: &'static Bar<dyn std::fmt::Debug> }, + //~^ ERROR the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time +} + +enum FooEnum2 { + Tuple(&'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) }; + // 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<dyn std::fmt::Debug>, | = 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>(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 + --> $DIR/field-implied-unsizing-wfcheck.rs:19:12 | LL | struct Bar<T>(T); | ^ - ...if indirection were used here: `Box<T>` @@ -19,25 +19,145 @@ LL | struct Bar<T>(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<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 + --> $DIR/field-implied-unsizing-wfcheck.rs:19: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 + --> $DIR/field-implied-unsizing-wfcheck.rs:19:12 | LL | struct Bar<T>(T); | ^ - ...if indirection were used here: `Box<T>` | | | 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<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:19: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:19:12 + | +LL | struct Bar<T>(T); + | ^ - ...if indirection were used here: `Box<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:15:11 + | +LL | Tuple(&'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:19: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:19:12 + | +LL | struct Bar<T>(T); + | ^ - ...if indirection were used here: `Box<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: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>(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:19:12 + | +LL | struct Bar<T>(T); + | ^ - ...if indirection were used here: `Box<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: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>(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:19:12 + | +LL | struct Bar<T>(T); + | ^ - ...if indirection were used here: `Box<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: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>(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:19:12 + | +LL | struct Bar<T>(T); + | ^ - ...if indirection were used here: `Box<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: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>(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:19:12 + | +LL | struct Bar<T>(T); + | ^ - ...if indirection were used here: `Box<T>` + | | + | this could be changed to `T: ?Sized`... + +error: aborting due to 8 previous errors For more information about this error, try `rustc --explain E0277`. |
