diff options
| author | Noah Lev <camelidcamel@gmail.com> | 2024-08-05 17:26:46 -0700 |
|---|---|---|
| committer | Noah Lev <camelidcamel@gmail.com> | 2024-08-05 17:37:12 -0700 |
| commit | 9479792cb4e6bdb0eba18d91af5ba3096c9007df (patch) | |
| tree | 63145f73731c50c9f92e2c9d412b195e89c5191d /tests/ui/structs | |
| parent | 18906754ccee76cebf92803c487942465c7f79a4 (diff) | |
| download | rust-9479792cb4e6bdb0eba18d91af5ba3096c9007df.tar.gz rust-9479792cb4e6bdb0eba18d91af5ba3096c9007df.zip | |
WF-check struct field types at construction site
Rustc of course already WF-checked the field types at the definition site, but for error tainting of consts to work properly, there needs to be an error emitted at the use site. Previously, with no use-site error, we proceeded with CTFE and ran into ICEs since we are running code with type errors. Emitting use-site errors also brings struct-like constructors more in line with fn-like constructors since they already emit use-site errors for WF issues.
Diffstat (limited to 'tests/ui/structs')
| -rw-r--r-- | tests/ui/structs/field-implied-unsizing-wfcheck.rs | 1 | ||||
| -rw-r--r-- | tests/ui/structs/field-implied-unsizing-wfcheck.stderr | 22 |
2 files changed, 22 insertions, 1 deletions
diff --git a/tests/ui/structs/field-implied-unsizing-wfcheck.rs b/tests/ui/structs/field-implied-unsizing-wfcheck.rs index 24da4b5e89d..981ff138de3 100644 --- a/tests/ui/structs/field-implied-unsizing-wfcheck.rs +++ b/tests/ui/structs/field-implied-unsizing-wfcheck.rs @@ -7,4 +7,5 @@ struct Bar<T>(T); fn main() { let x = Foo { nested: &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 c47918c7d16..79198c86141 100644 --- a/tests/ui/structs/field-implied-unsizing-wfcheck.stderr +++ b/tests/ui/structs/field-implied-unsizing-wfcheck.stderr @@ -18,6 +18,26 @@ LL | struct Bar<T>(T); | | | this could be changed to `T: ?Sized`... -error: aborting due to 1 previous error +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 + | +LL | let x = Foo { 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: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 2 previous errors For more information about this error, try `rustc --explain E0277`. |
