Skip to content

Taint const qualifs if a static is referenced that didn't pass wfcheck #123675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/rustc_const_eval/src/transform/check_consts/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
if self.tcx.is_thread_local_static(def_id) {
self.tcx.dcx().span_bug(span, "tls access is checked in `Rvalue::ThreadLocalRef`");
}
if let Some(def_id) = def_id.as_local()
&& let Err(guar) = self.tcx.at(span).check_well_formed(hir::OwnerId { def_id })
{
self.error_emitted = Some(guar);
}
self.check_op_spanned(ops::StaticAccess, span)
}

Expand Down
17 changes: 0 additions & 17 deletions tests/crashes/123153.rs

This file was deleted.

21 changes: 21 additions & 0 deletions tests/ui/statics/unsized_type2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! This test used to actually start evaluating the static even though
//! there were errors in typeck.
//! issue: rust-lang/rust#123153

pub struct Foo {
pub version: str,
}

pub struct Bar {
pub ok: &'static [&'static Bar],
pub bad: &'static Foo,
}

pub static WITH_ERROR: Foo = Foo { version: 0 };
//~^ ERROR the size for values of type `str` cannot be known at compilation time
//~| ERROR the size for values of type `str` cannot be known at compilation time
//~| ERROR mismatched types

pub static USE_WITH_ERROR: Bar = Bar { ok: &[], bad: &WITH_ERROR };

fn main() {}
37 changes: 37 additions & 0 deletions tests/ui/statics/unsized_type2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> $DIR/unsized_type2.rs:14:24
|
LL | pub static WITH_ERROR: Foo = Foo { version: 0 };
| ^^^ doesn't have a size known at compile-time
|
= help: within `Foo`, the trait `Sized` is not implemented for `str`, which is required by `Foo: Sized`
note: required because it appears within the type `Foo`
--> $DIR/unsized_type2.rs:5:12
|
LL | pub struct Foo {
| ^^^

error[E0277]: the size for values of type `str` cannot be known at compilation time
--> $DIR/unsized_type2.rs:14:30
|
LL | pub static WITH_ERROR: Foo = Foo { version: 0 };
| ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: within `Foo`, the trait `Sized` is not implemented for `str`, which is required by `Foo: Sized`
note: required because it appears within the type `Foo`
--> $DIR/unsized_type2.rs:5:12
|
LL | pub struct Foo {
| ^^^
= note: constant expressions must have a statically known size

error[E0308]: mismatched types
--> $DIR/unsized_type2.rs:14:45
|
LL | pub static WITH_ERROR: Foo = Foo { version: 0 };
| ^ expected `str`, found integer

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
Loading