From 36a981688e22f5189678085d045821370b193d60 Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Sat, 11 May 2024 11:50:20 -0700 Subject: [PATCH 1/2] Relax slice safety requirements Per https://github.com/rust-lang/rust/pull/116677#issuecomment-1945495786, the language as written promises too much. This PR relaxes the language to be consistent with current semantics. If and when #117945 is implemented, we can revert to the old language. --- core/src/primitive_docs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/primitive_docs.rs b/core/src/primitive_docs.rs index d8597369b9bf..331067b8975c 100644 --- a/core/src/primitive_docs.rs +++ b/core/src/primitive_docs.rs @@ -1468,7 +1468,7 @@ mod prim_usize {} /// boundary, the following invariants must generally be upheld: /// /// * `t` is aligned to `align_of_val(t)` -/// * `t` is dereferenceable for `size_of_val(t)` many bytes +/// * if `size_of_val(t) > 0`, then `t` is dereferenceable for `size_of_val(t)` many bytes /// /// If `t` points at address `a`, being "dereferenceable" for N bytes means that the memory range /// `[a, a + N)` is all contained within a single [allocated object]. From c195fa042538013cdbdf30d60411f7ab985e799d Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Sat, 11 May 2024 12:08:19 -0700 Subject: [PATCH 2/2] References must also be non-null --- core/src/primitive_docs.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/primitive_docs.rs b/core/src/primitive_docs.rs index 331067b8975c..8283fdc459be 100644 --- a/core/src/primitive_docs.rs +++ b/core/src/primitive_docs.rs @@ -1467,6 +1467,7 @@ mod prim_usize {} /// For all types, `T: ?Sized`, and for all `t: &T` or `t: &mut T`, when such values cross an API /// boundary, the following invariants must generally be upheld: /// +/// * `t` is non-null /// * `t` is aligned to `align_of_val(t)` /// * if `size_of_val(t) > 0`, then `t` is dereferenceable for `size_of_val(t)` many bytes ///