-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
fn foo(ptr1: *const u32, ptr2: *const u32) {
// In C these would be valid expressions:
let x = ptr1 + 5;
let y = ptr1[5];
let z = ptr2 - ptr1;
}
Current output
error[E0369]: cannot add `{integer}` to `*const u32`
--> src/lib.rs:3:18
|
3 | let x = ptr1 + 5;
| ---- ^ - {integer}
| |
| *const u32
error[E0608]: cannot index into a value of type `*const u32`
--> src/lib.rs:4:13
|
4 | let y = ptr1[5];
| ^^^^^^^
error[E0369]: cannot subtract `*const u32` from `*const u32`
--> src/lib.rs:5:18
|
5 | let z = ptr2 - ptr1;
| ---- ^ ---- *const u32
| |
| *const u32
Desired output
Suggest using .offset
(or .add
) for addition, and .offset_from
for subtraction.
jyn514 and dgiger42
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.