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/issues | |
| 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/issues')
| -rw-r--r-- | tests/ui/issues/issue-19380.rs | 1 | ||||
| -rw-r--r-- | tests/ui/issues/issue-19380.stderr | 25 |
2 files changed, 25 insertions, 1 deletions
diff --git a/tests/ui/issues/issue-19380.rs b/tests/ui/issues/issue-19380.rs index fce737cba18..8b3fe4d2b09 100644 --- a/tests/ui/issues/issue-19380.rs +++ b/tests/ui/issues/issue-19380.rs @@ -15,5 +15,6 @@ struct Bar { const FOO : Foo = Foo; const BAR : Bar = Bar { foos: &[&FOO]}; //~^ ERROR E0038 +//~| ERROR E0038 fn main() { } diff --git a/tests/ui/issues/issue-19380.stderr b/tests/ui/issues/issue-19380.stderr index f6244d9d44f..1d7aa6bd459 100644 --- a/tests/ui/issues/issue-19380.stderr +++ b/tests/ui/issues/issue-19380.stderr @@ -45,6 +45,29 @@ help: alternatively, consider constraining `qiz` so it does not apply to trait o LL | fn qiz() where Self: Sized; | +++++++++++++++++ -error: aborting due to 2 previous errors +error[E0038]: the trait `Qiz` cannot be made into an object + --> $DIR/issue-19380.rs:16:31 + | +LL | const BAR : Bar = Bar { foos: &[&FOO]}; + | ^^^^^^^ `Qiz` cannot be made into an object + | +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> + --> $DIR/issue-19380.rs:2:6 + | +LL | trait Qiz { + | --- this trait cannot be made into an object... +LL | fn qiz(); + | ^^^ ...because associated function `qiz` has no `self` parameter + = help: only type `Foo` implements the trait, consider using it directly instead +help: consider turning `qiz` into a method by giving it a `&self` argument + | +LL | fn qiz(&self); + | +++++ +help: alternatively, consider constraining `qiz` so it does not apply to trait objects + | +LL | fn qiz() where Self: Sized; + | +++++++++++++++++ + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0038`. |
