From 625b6f5844555c315d90081c5e542bcc2b82cc71 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sun, 2 Nov 2025 17:29:24 +0800 Subject: [PATCH] TypeId: make unstable layout/size explicit Or worded differently, explicitly remark non-stable-guarantee of `TypeId` layout and size. --- library/core/src/any.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/library/core/src/any.rs b/library/core/src/any.rs index 3ab95438c3ff3..655ec4dff309a 100644 --- a/library/core/src/any.rs +++ b/library/core/src/any.rs @@ -611,6 +611,15 @@ impl dyn Any + Send + Sync { /// noting that the hashes and ordering will vary between Rust releases. Beware /// of relying on them inside of your code! /// +/// # Layout +/// +/// Like other [`Rust`-representation][repr-rust] types, `TypeId`'s size and layout are unstable. +/// In particular, this means that you cannot rely on the size and layout of `TypeId` remaining the +/// same between Rust releases; they are subject to change without prior notice between Rust +/// releases. +/// +/// [repr-rust]: https://doc.rust-lang.org/reference/type-layout.html#r-layout.repr.rust.unspecified +/// /// # Danger of Improper Variance /// /// You might think that subtyping is impossible between two static types,