Open
Description
We currently produce fun diagnostics like
error: any use of this value will cause an error
--> $SRC_DIR/core/src/intrinsics.rs:LL:COL
|
LL | unsafe { copy_nonoverlapping(src, dst, count) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| memory access failed: pointer must be in-bounds at offset 8, but is outside bounds of alloc6 which has size 4
| inside `copy_nonoverlapping::<u32>` at $SRC_DIR/core/src/intrinsics.rs:LL:COL
| inside `std::ptr::read::<u32>` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
| inside `ptr::mut_ptr::<impl *mut u32>::read` at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
| inside `_MUT_READ` at $DIR/out_of_bounds_read.rs:15:37
|
::: $DIR/out_of_bounds_read.rs:15:5
|
LL | const _MUT_READ: u32 = unsafe { (PAST_END_PTR as *mut u32).read() };
| --------------------------------------------------------------------
Which I have multiple problems with (all of which are my fault 😛)
- the main message only makes sense when you realize this is a lint
- the diagnostic points to another crate's internals as the main span
- the local crate's span is pointing at the entire item, instead of the useful span that we have (last element in the stack trace)
I think we should adjust the diagnostic to report on the site in the currently compiling crate while still mentioning the backtrace in full, so something like
error: memory access failed: pointer must be in-bounds at offset 8, but is outside bounds of alloc6 which has size
--> $SRC_DIR/core/src/intrinsics.rs:LL:COL
|
LL | const _MUT_READ: u32 = unsafe { (PAST_END_PTR as *mut u32).read() };
| ^^^^^^^ in function call here
|
LL | unsafe { copy_nonoverlapping(src, dst, count) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ failure in external crate here
| inside `copy_nonoverlapping::<u32>` at $SRC_DIR/core/src/intrinsics.rs:LL:COL
| inside `std::ptr::read::<u32>` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
| inside `ptr::mut_ptr::<impl *mut u32>::read` at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
| inside `_MUT_READ` at $DIR/out_of_bounds_read.rs:15:37
cc @rust-lang/wg-diagnostics @rust-lang/wg-const-eval