-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 #89528 - FabianWolff:issue-89497, r=jackh726
Fix suggestion to borrow when casting from pointer to reference Fixes #89497.
- Loading branch information
Showing
7 changed files
with
80 additions
and
14 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,10 @@ | ||
// Regression test for issue #89497. | ||
|
||
// run-rustfix | ||
|
||
fn main() { | ||
let pointer: usize = &1_i32 as *const i32 as usize; | ||
let _reference: &'static i32 = unsafe { &*(pointer as *const i32) }; | ||
//~^ ERROR: non-primitive cast | ||
//~| HELP: consider borrowing the value | ||
} |
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,10 @@ | ||
// Regression test for issue #89497. | ||
|
||
// run-rustfix | ||
|
||
fn main() { | ||
let pointer: usize = &1_i32 as *const i32 as usize; | ||
let _reference: &'static i32 = unsafe { pointer as *const i32 as &'static i32 }; | ||
//~^ ERROR: non-primitive cast | ||
//~| HELP: consider borrowing the value | ||
} |
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,15 @@ | ||
error[E0605]: non-primitive cast: `*const i32` as `&'static i32` | ||
--> $DIR/issue-89497.rs:7:45 | ||
| | ||
LL | let _reference: &'static i32 = unsafe { pointer as *const i32 as &'static i32 }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast | ||
| | ||
help: consider borrowing the value | ||
| | ||
LL - let _reference: &'static i32 = unsafe { pointer as *const i32 as &'static i32 }; | ||
LL + let _reference: &'static i32 = unsafe { &*(pointer as *const i32) }; | ||
| | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0605`. |
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
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