Skip to content

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
bors added a commit that referenced this pull request Jun 27, 2025
Rollup of 9 pull requests

Successful merges:

 - #139858 (New const traits syntax)
 - #140809 (Reduce special casing for the panic runtime)
 - #142730 (suggest declaring modules when file found but module not defined)
 - #142806 (Normalize before computing ConstArgHasType goal in new solver)
 - #143046 (const validation: properly ignore zero-sized UnsafeCell)
 - #143092 (const checks for lifetime-extended temporaries: avoid 'top-level scope' terminology)
 - #143096 (tag_for_variant: properly pass TypingEnv)
 - #143104 (hir_analysis: prohibit `dyn PointeeSized`)
 - #143106 (gce: don't ICE on non-local const)

Failed merges:

 - #143036 (Remove support for `dyn*` from the compiler)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 2d59c4e into rust-lang:master Jun 28, 2025
10 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jun 28, 2025
rust-timer added a commit that referenced this pull request Jun 28, 2025
Rollup merge of #143046 - RalfJung:zst-unsafe-cell, r=lcnr,oli-obk

const validation: properly ignore zero-sized UnsafeCell

Fixes #142948
r? `@oli-obk`
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jun 28, 2025
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#139858 (New const traits syntax)
 - rust-lang/rust#140809 (Reduce special casing for the panic runtime)
 - rust-lang/rust#142730 (suggest declaring modules when file found but module not defined)
 - rust-lang/rust#142806 (Normalize before computing ConstArgHasType goal in new solver)
 - rust-lang/rust#143046 (const validation: properly ignore zero-sized UnsafeCell)
 - rust-lang/rust#143092 (const checks for lifetime-extended temporaries: avoid 'top-level scope' terminology)
 - rust-lang/rust#143096 (tag_for_variant: properly pass TypingEnv)
 - rust-lang/rust#143104 (hir_analysis: prohibit `dyn PointeeSized`)
 - rust-lang/rust#143106 (gce: don't ICE on non-local const)

Failed merges:

 - rust-lang/rust#143036 (Remove support for `dyn*` from the compiler)

r? `@ghost`
`@rustbot` modify labels: rollup
@RalfJung RalfJung deleted the zst-unsafe-cell branch June 28, 2025 07:24
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Jul 10, 2025
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#139858 (New const traits syntax)
 - rust-lang/rust#140809 (Reduce special casing for the panic runtime)
 - rust-lang/rust#142730 (suggest declaring modules when file found but module not defined)
 - rust-lang/rust#142806 (Normalize before computing ConstArgHasType goal in new solver)
 - rust-lang/rust#143046 (const validation: properly ignore zero-sized UnsafeCell)
 - rust-lang/rust#143092 (const checks for lifetime-extended temporaries: avoid 'top-level scope' terminology)
 - rust-lang/rust#143096 (tag_for_variant: properly pass TypingEnv)
 - rust-lang/rust#143104 (hir_analysis: prohibit `dyn PointeeSized`)
 - rust-lang/rust#143106 (gce: don't ICE on non-local const)

Failed merges:

 - rust-lang/rust#143036 (Remove support for `dyn*` from the compiler)

r? `@ghost`
`@rustbot` modify labels: rollup
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

{UnsafeCell,Cell}::from_mut on &mut [T; 0] then unsize-coerced in consteval reports UB in safe code
5 participants