From 35126d9b0c71d23011e23db82b20cec480222a36 Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Mon, 17 Mar 2025 07:29:11 -0700 Subject: [PATCH 1/3] =?UTF-8?q?Mention=20that=20=E2=80=9Cevery=20address?= =?UTF-8?q?=E2=80=9D=20=E2=89=A0=20=E2=80=9Cevery=20pointer=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds a note in case people are tempted to interpret “`usize` ... can represent every memory address” as saying that pointer→usize→pointer roundtrips are definitely okay. Since the reference does not yet discuss provenance and that’s a much larger matter, I have merely linked to relevant existing documentation inside and outside the reference. --- src/types/numeric.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/types/numeric.md b/src/types/numeric.md index 5717d10b3..d65a1639f 100644 --- a/src/types/numeric.md +++ b/src/types/numeric.md @@ -40,6 +40,10 @@ r[type.numeric.int.size.usize] The `usize` type is an unsigned integer type with the same number of bits as the platform's pointer type. It can represent every memory address in the process. +> [!NOTE] +> While a `usize` can represent every *address*, converting a *pointer* to a `usize` is not necessarily a reversible operation. +> For more information, see the documentation for [type cast expressions] and [`std::ptr`]. + r[type.numeric.int.size.isize] The `isize` type is a signed integer type with the same number of bits as the platform's pointer type. The theoretical upper bound on object and array size @@ -58,3 +62,5 @@ r[type.numeric.validity] For every numeric type, `T`, the bit validity of `T` is equivalent to the bit validity of `[u8; size_of::()]`. An uninitialized byte is not a valid `u8`. + +[type cast expressions]: ../expressions/operator-expr.html#type-cast-expressions From c090f4662dbc15da3247b27b30dcfd48167a5aac Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Thu, 20 Mar 2025 08:58:59 -0700 Subject: [PATCH 2/3] Add mention of provenance. Co-authored-by: Josh Triplett --- src/types/numeric.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/numeric.md b/src/types/numeric.md index d65a1639f..1f9c05e37 100644 --- a/src/types/numeric.md +++ b/src/types/numeric.md @@ -42,7 +42,7 @@ platform's pointer type. It can represent every memory address in the process. > [!NOTE] > While a `usize` can represent every *address*, converting a *pointer* to a `usize` is not necessarily a reversible operation. -> For more information, see the documentation for [type cast expressions] and [`std::ptr`]. +> For more information, see the documentation for [type cast expressions], [`std::ptr`], and [provenance][std::ptr#provenance] in particular. r[type.numeric.int.size.isize] The `isize` type is a signed integer type with the same number of bits as the From 7fbcb20c69918d119fa6636aae031c18be2a9181 Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Thu, 20 Mar 2025 13:48:30 -0700 Subject: [PATCH 3/3] Adjust link. Co-authored-by: Ralf Jung --- src/types/numeric.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/numeric.md b/src/types/numeric.md index 1f9c05e37..d040fa746 100644 --- a/src/types/numeric.md +++ b/src/types/numeric.md @@ -63,4 +63,4 @@ r[type.numeric.validity] For every numeric type, `T`, the bit validity of `T` is equivalent to the bit validity of `[u8; size_of::()]`. An uninitialized byte is not a valid `u8`. -[type cast expressions]: ../expressions/operator-expr.html#type-cast-expressions +[type cast expressions]: ../expressions/operator-expr.md#type-cast-expressions