-
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.
Auto merge of #84228 - SkiFire13:fix-84213, r=estebank
Suggest to borrow after failing to cast from T to *const/mut T Fixes #84213
- Loading branch information
Showing
4 changed files
with
70 additions
and
0 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,15 @@ | ||
// run-rustfix | ||
|
||
struct Something { | ||
pub field: u32, | ||
} | ||
|
||
fn main() { | ||
let mut something = Something { field: 1337 }; | ||
|
||
let _pointer_to_something = &something as *const Something; | ||
//~^ ERROR: non-primitive cast | ||
|
||
let _mut_pointer_to_something = &mut something as *mut Something; | ||
//~^ ERROR: non-primitive cast | ||
} |
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 @@ | ||
// run-rustfix | ||
|
||
struct Something { | ||
pub field: u32, | ||
} | ||
|
||
fn main() { | ||
let mut something = Something { field: 1337 }; | ||
|
||
let _pointer_to_something = something as *const Something; | ||
//~^ ERROR: non-primitive cast | ||
|
||
let _mut_pointer_to_something = something as *mut Something; | ||
//~^ ERROR: non-primitive cast | ||
} |
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,25 @@ | ||
error[E0605]: non-primitive cast: `Something` as `*const Something` | ||
--> $DIR/issue-84213.rs:10:33 | ||
| | ||
LL | let _pointer_to_something = something as *const Something; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast | ||
| | ||
help: borrow the value for the cast to be valid | ||
| | ||
LL | let _pointer_to_something = &something as *const Something; | ||
| ^ | ||
|
||
error[E0605]: non-primitive cast: `Something` as `*mut Something` | ||
--> $DIR/issue-84213.rs:13:37 | ||
| | ||
LL | let _mut_pointer_to_something = something as *mut Something; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast | ||
| | ||
help: borrow the value for the cast to be valid | ||
| | ||
LL | let _mut_pointer_to_something = &mut something as *mut Something; | ||
| ^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0605`. |