Skip to content

Unhelphful stacked borrows diagnostic span  #2536

Closed
@SparkyPotato

Description

@SparkyPotato

Running https://gist.github.com/SparkyPotato/a32487ed62d8c28acbac2d4df9129af7 in miri, it errors with:

error: Undefined Behavior: attempting a write access using <3540> at alloc1752[0x18], but that tag does not exist in the borrow stack for this location
   --> src/main.rs:152:3
    |
152 |         *a = 123;
    |         ^^^^^^^^
    |         |
    |         attempting a write access using <3540> at alloc1752[0x18], but that tag does not exist in the borrow stack for this location
    |         this error occurs as part of an access at alloc1752[0x18..0x1c]
    |
    = 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: <3540> was created by a SharedReadWrite retag at offsets [0x18..0x1c]
   --> src/main.rs:130:31
    |
130 |                 Ok(NonNull::new_unchecked(from_raw_parts_mut(target, layout.size())))
    |                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: <3540> was later invalidated at offsets [0x18..0x100018] by a Unique FnEntry retag
   --> src/main.rs:150:11
    |
150 |         let b = arena.allocate(Layout::new::<u32>()).unwrap().as_ptr() as *mut u32;
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: backtrace:
    = note: inside `main` at src/main.rs:152:3

However, the stacked borrow violation is in lines 123 and 126, where data: [u8] is autorefed to a &mut [u8] for [u8]::as_mut_ptr.

While the span is technically correct, it doesn't help when trying to track where the reference actually came from.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticserrors and warnings emitted by miri

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions