Skip to content

const validation: properly ignore zero-sized UnsafeCell #143046

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

RalfJung
Copy link
Member

Fixes #142948
r? @oli-obk

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 26, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 26, 2025

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

let zst = self
.ecx
.size_and_align_of(&val.meta(), &val.layout)?
.is_some_and(|(s, _a)| s.bytes() == 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems very footgunny, why do is_zst and size_and_align_of(&val.meta(), &val.layout).is_some_and(|(s, _a)| s.bytes() == 0) differ. When is using is_zst actually correct?

Okay, this is because we're not checking whether the type itself is a ZST, but that the value is a zero-sized. So we don't use is_zst to also handle slices and trait objects. Can you add this as a comment to the code in visit_value?

after that r=me

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is using is_zst actually correct?

Basically this is must_be_zst, but it can miss types that are only dynamically zero-sized.

@rustbot
Copy link
Collaborator

rustbot commented Jun 26, 2025

The Miri subtree was changed

cc @rust-lang/miri

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@RalfJung
Copy link
Member Author

I also added a 2nd commit making the size_and_align_of APIs in the interpreter a bit nicer.

@oli-obk
Copy link
Contributor

oli-obk commented Jun 26, 2025

@bors r=lcnr,oli-obk

@bors
Copy link
Collaborator

bors commented Jun 26, 2025

📌 Commit 7de39f5 has been approved by lcnr,oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
5 participants