-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve error message for calling a method on a raw pointer with an u…
…nknown pointee, and add some tests
- Loading branch information
1 parent
917b0b6
commit b19466a
Showing
7 changed files
with
63 additions
and
8 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
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
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,28 @@ | ||
// edition: 2018 | ||
|
||
// tests that the pointee type of a raw pointer must be known to call methods on it | ||
// see also: `tests/ui/editions/edition-raw-pointer-method-2018.rs` | ||
|
||
fn main() { | ||
let val = 1_u32; | ||
let ptr = &val as *const u32; | ||
unsafe { | ||
let _a: i32 = (ptr as *const _).read(); | ||
//~^ ERROR cannot call a method on a raw pointer with an unknown pointee type [E0699] | ||
let b = ptr as *const _; | ||
let _b: u8 = b.read(); | ||
//~^ ERROR cannot call a method on a raw pointer with an unknown pointee type [E0699] | ||
let _c = (ptr as *const u8).read(); // we know the type here | ||
} | ||
|
||
let mut val = 2_u32; | ||
let ptr = &mut val as *mut u32; | ||
unsafe { | ||
let _a: i32 = (ptr as *mut _).read(); | ||
//~^ ERROR cannot call a method on a raw pointer with an unknown pointee type [E0699] | ||
let b = ptr as *mut _; | ||
b.write(10); | ||
//~^ ERROR cannot call a method on a raw pointer with an unknown pointee type [E0699] | ||
(ptr as *mut i32).write(1000); // we know the type 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,27 @@ | ||
error[E0699]: cannot call a method on a raw pointer with an unknown pointee type | ||
--> $DIR/call_method_unknown_pointee.rs:10:41 | ||
| | ||
LL | let _a: i32 = (ptr as *const _).read(); | ||
| ^^^^ | ||
|
||
error[E0699]: cannot call a method on a raw pointer with an unknown pointee type | ||
--> $DIR/call_method_unknown_pointee.rs:13:24 | ||
| | ||
LL | let _b: u8 = b.read(); | ||
| ^^^^ | ||
|
||
error[E0699]: cannot call a method on a raw pointer with an unknown pointee type | ||
--> $DIR/call_method_unknown_pointee.rs:21:39 | ||
| | ||
LL | let _a: i32 = (ptr as *mut _).read(); | ||
| ^^^^ | ||
|
||
error[E0699]: cannot call a method on a raw pointer with an unknown pointee type | ||
--> $DIR/call_method_unknown_pointee.rs:24:11 | ||
| | ||
LL | b.write(10); | ||
| ^^^^^ | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0699`. |