forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#95920 - compiler-errors:cast-suggestion-spa…
…n, r=oli-obk use `Span::find_ancestor_inside` to get right span in CastCheck This is a quick fix. This bad suggestion likely lives in other places... but thought it would be useful to fix all of the CastCheck ones first. Let me know if reviewer would prefer I add more tests for each of the diagnostics in CastCheck, or would like to do a more thorough review of other suggestions that use spans in typeck. I would also be open to further suggestions on how to better expose an API that gives us the "best" span for a diagnostic suggestion. Fixed rust-lang#95919
- Loading branch information
Showing
3 changed files
with
42 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |