Skip to content

Commit

Permalink
Test more cases of WF-checking for fields
Browse files Browse the repository at this point in the history
  • Loading branch information
camelid committed Aug 6, 2024
1 parent 9479792 commit 2f4603b
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 10 deletions.
25 changes: 23 additions & 2 deletions tests/ui/structs/field-implied-unsizing-wfcheck.rs
Original file line number Diff line number Diff line change
@@ -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
}
136 changes: 128 additions & 8 deletions tests/ui/structs/field-implied-unsizing-wfcheck.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,158 @@ 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>`
| |
| 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`.

0 comments on commit 2f4603b

Please sign in to comment.