Skip to content

Values and Sized types are not larger than isize::MAX#2202

Open
joshlf wants to merge 4 commits intorust-lang:masterfrom
joshlf:patch-10
Open

Values and Sized types are not larger than isize::MAX#2202
joshlf wants to merge 4 commits intorust-lang:masterfrom
joshlf:patch-10

Conversation

@joshlf
Copy link
Contributor

@joshlf joshlf commented Mar 6, 2026

See #t-opsem > Constraints on abstract values? @ 💬 for context.

For Sized types, we nearly already guarantee this by implication. If we assume that Layout::new<T>() -> Layout can't fail to compile or panic at runtime, then it implies that, for any T: Sized, it is possible to acquire a Layout describing that T. Layout, in turn, guarantees that:

The size, when rounded up to the nearest multiple of align, does not overflow isize (i.e., the rounded value will always be less than or equal to isize::MAX).

This is also already guaranteed for any Rust allocation, although in theory it's possible that:

  • A value could live somewhere other than an allocation
  • A type could be compiled that is never instantiated, and thus the allocation constraint doesn't constrain the size of the type itself

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Mar 6, 2026
@joshlf
Copy link
Contributor Author

joshlf commented Mar 6, 2026

r? @ehuss

cc @RalfJung

Copy link
Member

@programmerjake programmerjake left a comment

Choose a reason for hiding this comment

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

Co-authored-by: Jacob Lifshay <programmerjake@gmail.com>
@joshlf joshlf changed the title Sized types are not larger than isize::MAX Values and Sized types are not larger than isize::MAX Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: The marked PR is awaiting review from a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants