use find_ancestor_inside to get right span in CastCheck

This commit is contained in:
Michael Goulet 2022-04-10 22:15:31 -07:00
parent 18f32b73bd
commit d2b1bb8a9b
3 changed files with 42 additions and 18 deletions

View file

@ -0,0 +1,12 @@
// Test to make sure we suggest "consider casting" on the right span
macro_rules! foo {
() => { 0 }
}
fn main() {
let x = foo!() as *const [u8];
//~^ ERROR cannot cast `usize` to a pointer that is wide
//~| NOTE creating a `*const [u8]` requires both an address and a length
//~| NOTE consider casting this expression to `*const ()`, then using `core::ptr::from_raw_parts`
}

View file

@ -0,0 +1,11 @@
error[E0606]: cannot cast `usize` to a pointer that is wide
--> $DIR/cast-macro-lhs.rs:8:23
|
LL | let x = foo!() as *const [u8];
| ------ ^^^^^^^^^^^ creating a `*const [u8]` requires both an address and a length
| |
| consider casting this expression to `*const ()`, then using `core::ptr::from_raw_parts`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0606`.