Skip to content

Eliminate pointer->reference->pointer during downcast#452

Merged
dtolnay merged 2 commits into
masterfrom
downcast
Jun 25, 2026
Merged

Eliminate pointer->reference->pointer during downcast#452
dtolnay merged 2 commits into
masterfrom
downcast

Conversation

@dtolnay

@dtolnay dtolnay commented Jun 25, 2026

Copy link
Copy Markdown
Owner

Fixes #451.

dtolnay added 2 commits June 25, 2026 13:40
    test test_downcast_mut ... error: Undefined Behavior: trying to retag from <137701> for Unique permission at alloc44937[0x38], but that tag only grants SharedReadOnly permission for this location
       --> src/ptr.rs:170:18
        |
    170 |         unsafe { &mut *self.ptr.as_ptr() }
        |                  ^^^^^^^^^^^^^^^^^^^^^^^ this error occurs as part of retag at alloc44937[0x38..0x50]
        |
        = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
        = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
    help: <137701> was created by a SharedReadOnly retag at offsets [0x38..0x50]
       --> src/ptr.rs:89:18
        |
     89 |             ptr: NonNull::from(ptr),
        |                  ^^^^^^^^^^^^^^^^^^
        = note: this is on thread `test_downcast_mut`
        = note: stack backtrace:
                0: anyhow::ptr::Mut::<'_, HighLevel>::deref_mut
                    at src/ptr.rs:170:18: 170:41
                1: anyhow::error::<impl anyhow::Error>::downcast_mut::<HighLevel>
                    at src/error.rs:560:18: 560:46
                2: test_downcast_mut
                    at tests/test_context.rs:171:5: 171:36
                3: test_downcast_mut::{closure#0}
                    at tests/test_context.rs:168:23: 168:23
@dtolnay dtolnay merged commit e621bd3 into master Jun 25, 2026
12 checks passed
@dtolnay dtolnay deleted the downcast branch June 25, 2026 20:42
eleboucher pushed a commit to eleboucher/towonel that referenced this pull request Jun 26, 2026
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [anyhow](https://github.com/dtolnay/anyhow) | workspace.dependencies | patch | `1.0.102` → `1.0.103` |

---

### Release Notes

<details>
<summary>dtolnay/anyhow (anyhow)</summary>

### [`v1.0.103`](https://github.com/dtolnay/anyhow/releases/tag/1.0.103)

[Compare Source](dtolnay/anyhow@1.0.102...1.0.103)

- Fix Stacked Borrows violation (UB) in `Error::downcast_mut` ([#&#8203;451](dtolnay/anyhow#451), [#&#8203;452](dtolnay/anyhow#452))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMDEuMSIsInVwZGF0ZWRJblZlciI6IjQzLjEwMS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJ0eXBlL3BhdGNoIl19-->

Reviewed-on: https://codeberg.org/towonel/towonel/pulls/43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UB in Error::downcast_mut

1 participant