Uh oh!
There was an error while loading. Please reload this page.
add #[rustc_no_writable] to slice::get_unchecked_mut - #157202
Conversation
rustbot
commented
May 31, 2026
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
quiode
commented
May 31, 2026
r? @RalfJung |
rustbot
commented
May 31, 2026
|
| @@ -681,6 +681,7 @@ impl<T> [T] { | |||
| #[must_use] | |||
| #[track_caller] | |||
| #[rustc_const_unstable(feature = "const_index", issue = "143775")] | |||
| #[rustc_no_writable] | |||
There was a problem hiding this comment.
Should this get an annotation of some kind (e.g., "FIXME: #xxx")? I assume the intent is not to guarantee that we don't have compiler-added writes of the full slice, maybe with the long-term intent being that users move to using raw pointer functions where they need that (https://doc.rust-lang.org/nightly/std/primitive.pointer.html#method.get_unchecked_mut)?
There was a problem hiding this comment.
Personally I think this is fine to guarantee. But for now the attribute is experimental anyway.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
RalfJung
commented
Jun 1, 2026
@rustbot author |
rustbot
commented
Jun 1, 2026
Reminder, once the PR becomes ready for a review, use |
rustbot
commented
Jun 7, 2026
The Miri subtree was changed cc @rust-lang/miri |
This comment has been minimized.
This comment has been minimized.
quiode
commented
Jun 7, 2026
The proposed test wasn't exactly the pattern I tried to fix (and also still fails with the attribute). It was more something like this: https://github.com/quiode/rust/blob/ignore-list/src/tools/miri/tests/fail/tree_borrows/implicit_writes/libc_recv.rs or https://github.com/quiode/rust/blob/ignore-list/src/tools/miri/tests/fail-dep/tree_borrows/implicit_writes/crates/fs-read.rs. I tried to replicate this in the new test, which fails without the attribute but passes with it. @rustbot ready |
I think it is the same pattern, but we'd need to decorate more functions... that pattern should ideally work. (https://rust.godbolt.org/z/TreEYqfW8) But meanwhile we can land this. |
This comment has been minimized.
This comment has been minimized.
* add #[rustc_no_writable] to slice::get_unchecked_mut * add #[rustc_no_writable] to slice::get_mut * add unchecked_mut miri test
🔨 3 commits were squashed into 42d7bf1. |
566bf0b to
42d7bf1CompareRalfJung
commented
Jun 12, 2026
@bors r+ rollup |
It looks like if I run that test with your branch, there's no UB reported? So it does actually seem to help? EDIT: Never mind I tested the wrong thing. |
…fns, r=RalfJung add #[rustc_no_writable] to slice::get_unchecked_mut This PR adds the `#[rustc_no_writable]` attribute introduced in rust-lang#155207 to the `slice::get_unchecked_mut` function. Two library functions already received this attribute, as they were known to cause problems with the llvm writable attribute and tree borrows. Since that PR, I ran Miri on the 30'000 most downloaded crates to see what kind of code is now UB under Tree Borrows + implicit writes, using the detection implemented in rust-lang/miri#4947. Adding this attribute to ignore checking for this function reduced the new UB introduced by more than 75%, meaning that instead of 19000 tests in 1700 crates having a difference, now only 3500 in 350 crates show a difference (measurement still running).
…fns, r=RalfJung add #[rustc_no_writable] to slice::get_unchecked_mut This PR adds the `#[rustc_no_writable]` attribute introduced in rust-lang#155207 to the `slice::get_unchecked_mut` function. Two library functions already received this attribute, as they were known to cause problems with the llvm writable attribute and tree borrows. Since that PR, I ran Miri on the 30'000 most downloaded crates to see what kind of code is now UB under Tree Borrows + implicit writes, using the detection implemented in rust-lang/miri#4947. Adding this attribute to ignore checking for this function reduced the new UB introduced by more than 75%, meaning that instead of 19000 tests in 1700 crates having a difference, now only 3500 in 350 crates show a difference (measurement still running).
…fns, r=RalfJung add #[rustc_no_writable] to slice::get_unchecked_mut This PR adds the `#[rustc_no_writable]` attribute introduced in rust-lang#155207 to the `slice::get_unchecked_mut` function. Two library functions already received this attribute, as they were known to cause problems with the llvm writable attribute and tree borrows. Since that PR, I ran Miri on the 30'000 most downloaded crates to see what kind of code is now UB under Tree Borrows + implicit writes, using the detection implemented in rust-lang/miri#4947. Adding this attribute to ignore checking for this function reduced the new UB introduced by more than 75%, meaning that instead of 19000 tests in 1700 crates having a difference, now only 3500 in 350 crates show a difference (measurement still running).
…uwer Rollup of 17 pull requests Successful merges: - #156950 (Staticlib rename internal symbols) - #157322 (test pre-stabilization items on CI) - #157490 (Add field-wise CoerceShared reborrow tests) - #157655 (Make Share::share final and improve docs) - #157688 (Create experimental test job `aarch64-apple-macos-26` for evaluating `macos-26` runner images) - #157796 (rustdoc: Some more lazy formatting) - #157069 (Test that you can't implement Unpin for a compiler-generated future using TAIT) - #157202 (add #[rustc_no_writable] to slice::get_unchecked_mut) - #157622 (Disable retagging for variadic arguments in const-eval) - #157684 (-Zassumptions-on-binders: insert empty assumptions when entering binders in the solver) - #157695 (Extend capabilities of `TypeFoldable_Generic`) - #157752 (Rename `errors.rs` file to `diagnostics.rs` (6/N)) - #157766 (interpret: avoid computing layout of sized raw pointee) - #157785 (fuchsia: Support AddressSanitizer on riscv64gc-unknown-fuchsia) - #157795 (revert 157013) - #157798 (Prevent approving PRs that wait for Crater or formal decisions) - #157803 (Rename `errors.rs` file to `diagnostics.rs` (7/N))
…uwer Rollup of 17 pull requests Successful merges: - #156950 (Staticlib rename internal symbols) - #157322 (test pre-stabilization items on CI) - #157490 (Add field-wise CoerceShared reborrow tests) - #157655 (Make Share::share final and improve docs) - #157688 (Create experimental test job `aarch64-apple-macos-26` for evaluating `macos-26` runner images) - #157796 (rustdoc: Some more lazy formatting) - #157069 (Test that you can't implement Unpin for a compiler-generated future using TAIT) - #157202 (add #[rustc_no_writable] to slice::get_unchecked_mut) - #157622 (Disable retagging for variadic arguments in const-eval) - #157684 (-Zassumptions-on-binders: insert empty assumptions when entering binders in the solver) - #157695 (Extend capabilities of `TypeFoldable_Generic`) - #157752 (Rename `errors.rs` file to `diagnostics.rs` (6/N)) - #157766 (interpret: avoid computing layout of sized raw pointee) - #157785 (fuchsia: Support AddressSanitizer on riscv64gc-unknown-fuchsia) - #157795 (revert 157013) - #157798 (Prevent approving PRs that wait for Crater or formal decisions) - #157803 (Rename `errors.rs` file to `diagnostics.rs` (7/N))
…fns, r=RalfJung add #[rustc_no_writable] to slice::get_unchecked_mut This PR adds the `#[rustc_no_writable]` attribute introduced in rust-lang#155207 to the `slice::get_unchecked_mut` function. Two library functions already received this attribute, as they were known to cause problems with the llvm writable attribute and tree borrows. Since that PR, I ran Miri on the 30'000 most downloaded crates to see what kind of code is now UB under Tree Borrows + implicit writes, using the detection implemented in rust-lang/miri#4947. Adding this attribute to ignore checking for this function reduced the new UB introduced by more than 75%, meaning that instead of 19000 tests in 1700 crates having a difference, now only 3500 in 350 crates show a difference (measurement still running).
…uwer Rollup of 23 pull requests Successful merges: - #144220 (Add powerpc64-unknown-linux-gnuelfv2 target) - #153238 (debuginfo: slices are DW_TAG_array_type's) - #157112 (Update aarch64-unknown-freebsd target description) - #157322 (test pre-stabilization items on CI) - #157348 (Don't track cwd for `-Zremap-cwd-prefix` in incremental compilation) - #157490 (Add field-wise CoerceShared reborrow tests) - #157655 (Make Share::share final and improve docs) - #157672 (Region inference: Simplify initialisation of region values) - #157680 (Require `#[pin_v2]` for explicit pin-projection patterns) - #157688 (Create experimental test job `aarch64-apple-macos-26` for evaluating `macos-26` runner images) - #157796 (rustdoc: Some more lazy formatting) - #157818 (miri subtree update) - #157069 (Test that you can't implement Unpin for a compiler-generated future using TAIT) - #157079 (Don't recover `&raw EXPR` as a missing comma) - #157202 (add #[rustc_no_writable] to slice::get_unchecked_mut) - #157622 (Disable retagging for variadic arguments in const-eval) - #157684 (-Zassumptions-on-binders: insert empty assumptions when entering binders in the solver) - #157695 (Extend capabilities of `TypeFoldable_Generic`) - #157766 (interpret: avoid computing layout of sized raw pointee) - #157785 (fuchsia: Support AddressSanitizer on riscv64gc-unknown-fuchsia) - #157795 (revert 157013) - #157798 (Prevent approving PRs that wait for Crater or formal decisions) - #157803 (Rename `errors.rs` file to `diagnostics.rs` (7/N)) Failed merges: - #157752 (Rename `errors.rs` file to `diagnostics.rs` (6/N))
Uh oh!
There was an error while loading. Please reload this page.
…uwer Rollup of 23 pull requests Successful merges: - rust-lang/rust#144220 (Add powerpc64-unknown-linux-gnuelfv2 target) - rust-lang/rust#153238 (debuginfo: slices are DW_TAG_array_type's) - rust-lang/rust#157112 (Update aarch64-unknown-freebsd target description) - rust-lang/rust#157322 (test pre-stabilization items on CI) - rust-lang/rust#157348 (Don't track cwd for `-Zremap-cwd-prefix` in incremental compilation) - rust-lang/rust#157490 (Add field-wise CoerceShared reborrow tests) - rust-lang/rust#157655 (Make Share::share final and improve docs) - rust-lang/rust#157672 (Region inference: Simplify initialisation of region values) - rust-lang/rust#157680 (Require `#[pin_v2]` for explicit pin-projection patterns) - rust-lang/rust#157688 (Create experimental test job `aarch64-apple-macos-26` for evaluating `macos-26` runner images) - rust-lang/rust#157796 (rustdoc: Some more lazy formatting) - rust-lang/rust#157818 (miri subtree update) - rust-lang/rust#157069 (Test that you can't implement Unpin for a compiler-generated future using TAIT) - rust-lang/rust#157079 (Don't recover `&raw EXPR` as a missing comma) - rust-lang/rust#157202 (add #[rustc_no_writable] to slice::get_unchecked_mut) - rust-lang/rust#157622 (Disable retagging for variadic arguments in const-eval) - rust-lang/rust#157684 (-Zassumptions-on-binders: insert empty assumptions when entering binders in the solver) - rust-lang/rust#157695 (Extend capabilities of `TypeFoldable_Generic`) - rust-lang/rust#157766 (interpret: avoid computing layout of sized raw pointee) - rust-lang/rust#157785 (fuchsia: Support AddressSanitizer on riscv64gc-unknown-fuchsia) - rust-lang/rust#157795 (revert 157013) - rust-lang/rust#157798 (Prevent approving PRs that wait for Crater or formal decisions) - rust-lang/rust#157803 (Rename `errors.rs` file to `diagnostics.rs` (7/N)) Failed merges: - rust-lang/rust#157752 (Rename `errors.rs` file to `diagnostics.rs` (6/N))
…, r=RalfJung add rustc_no_writable to mem::forget and structs it uses This builds upon rust-lang#155207 and is similar to rust-lang#157202. It adds the `#[rustc_no_writable]` attribute to `mem::forget` and the `MaybeDangling` and `ManuallyDrop`. This makes Miri with Tree Borrows and implicit writes no longer report UB for a test in `derive_more`. As the pattern itself is quite unclean, and I have not seen `mem::forget` to cause trouble before with implicit writes, I'm not sure how much sense it makes to add it to `mem::forget`. The test works unter Tree Borrows, but fails already for Stacked Borrows. Thus I would be happy for some guidance if the attribute makes sense here @RalfJung@JoJoDeveloping.
Rollup merge of #159181 - quiode:mem--forget-implicit-writes, r=RalfJung add rustc_no_writable to mem::forget and structs it uses This builds upon #155207 and is similar to #157202. It adds the `#[rustc_no_writable]` attribute to `mem::forget` and the `MaybeDangling` and `ManuallyDrop`. This makes Miri with Tree Borrows and implicit writes no longer report UB for a test in `derive_more`. As the pattern itself is quite unclean, and I have not seen `mem::forget` to cause trouble before with implicit writes, I'm not sure how much sense it makes to add it to `mem::forget`. The test works unter Tree Borrows, but fails already for Stacked Borrows. Thus I would be happy for some guidance if the attribute makes sense here @RalfJung@JoJoDeveloping.
add rustc_no_writable to mem::forget and structs it uses This builds upon rust-lang/rust#155207 and is similar to rust-lang/rust#157202. It adds the `#[rustc_no_writable]` attribute to `mem::forget` and the `MaybeDangling` and `ManuallyDrop`. This makes Miri with Tree Borrows and implicit writes no longer report UB for a test in `derive_more`. As the pattern itself is quite unclean, and I have not seen `mem::forget` to cause trouble before with implicit writes, I'm not sure how much sense it makes to add it to `mem::forget`. The test works unter Tree Borrows, but fails already for Stacked Borrows. Thus I would be happy for some guidance if the attribute makes sense here @RalfJung@JoJoDeveloping.
View all comments
This PR adds the
#[rustc_no_writable]attribute introduced in #155207 to theslice::get_unchecked_mutfunction.Two library functions already received this attribute, as they were known to cause problems with the llvm writable attribute and tree borrows. Since that PR, I ran Miri on the 30'000 most downloaded crates to see what kind of code is now UB under Tree Borrows + implicit writes, using the detection implemented in rust-lang/miri#4947. Adding this attribute to ignore checking for this function reduced the new UB introduced by more than 75%, meaning that instead of 19000 tests in 1700 crates having a difference, now only 3500 in 350 crates show a difference (measurement still running).