-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix suggestion to convert dereference of raw pointer to ref
- Loading branch information
1 parent
d8a6409
commit 8d59545
Showing
4 changed files
with
64 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,19 @@ | ||
//@ run-rustfix | ||
// Regression test for #135580: check that we do not suggest to simply drop | ||
// the `*` to make the types match when the source is a raw pointer while | ||
// the target type is a reference. | ||
|
||
struct S; | ||
|
||
fn main() { | ||
let mut s = S; | ||
let x = &raw const s; | ||
let _: &S = unsafe { &*x }; | ||
//~^ ERROR mismatched types | ||
//~| HELP consider borrowing here | ||
|
||
let x = &raw mut s; | ||
let _: &mut S = unsafe { &mut *x }; | ||
//~^ ERROR mismatched types | ||
//~| HELP consider mutably borrowing here | ||
} |
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,19 @@ | ||
//@ run-rustfix | ||
// Regression test for #135580: check that we do not suggest to simply drop | ||
// the `*` to make the types match when the source is a raw pointer while | ||
// the target type is a reference. | ||
|
||
struct S; | ||
|
||
fn main() { | ||
let mut s = S; | ||
let x = &raw const s; | ||
let _: &S = unsafe { *x }; | ||
//~^ ERROR mismatched types | ||
//~| HELP consider borrowing here | ||
|
||
let x = &raw mut s; | ||
let _: &mut S = unsafe { *x }; | ||
//~^ ERROR mismatched types | ||
//~| HELP consider mutably borrowing here | ||
} |
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[E0308]: mismatched types | ||
--> $DIR/raw-to-ref.rs:11:26 | ||
| | ||
LL | let _: &S = unsafe { *x }; | ||
| ^^ expected `&S`, found `S` | ||
| | ||
help: consider borrowing here | ||
| | ||
LL | let _: &S = unsafe { &*x }; | ||
| + | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/raw-to-ref.rs:16:30 | ||
| | ||
LL | let _: &mut S = unsafe { *x }; | ||
| ^^ expected `&mut S`, found `S` | ||
| | ||
help: consider mutably borrowing here | ||
| | ||
LL | let _: &mut S = unsafe { &mut *x }; | ||
| ++++ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |