Remove bad cast in test, cover more cases

This commit is contained in:
Joe Ranweiler 2021-06-22 18:44:04 -07:00
parent 48fa1dc8bb
commit d2087ad00d
2 changed files with 61 additions and 12 deletions

View file

@ -1,12 +1,18 @@
fn main() {
unsafe {
let x = &() as *const ();
x.offset(0);
x.wrapping_add(0);
x.sub(0);
x.wrapping_sub(0);
let m = &mut () as *mut ();
m.offset(0);
m.wrapping_add(0);
m.sub(0);
m.wrapping_sub(0);
let y = &1 as *const u8;
let c = &() as *const ();
c.offset(0);
c.wrapping_add(0);
c.sub(0);
c.wrapping_sub(0);
let y = &1 as *const i32;
y.offset(0);
}
}

View file

@ -1,9 +1,52 @@
error[E0606]: casting `&i32` as `*const u8` is invalid
--> $DIR/zero_offset.rs:9:17
error: offset calculation on zero-sized value
--> $DIR/zero_offset.rs:4:9
|
LL | let y = &1 as *const u8;
| ^^^^^^^^^^^^^^^
LL | m.offset(0);
| ^^^^^^^^^^^
|
= note: `#[deny(clippy::zst_offset)]` on by default
error: aborting due to previous error
error: offset calculation on zero-sized value
--> $DIR/zero_offset.rs:5:9
|
LL | m.wrapping_add(0);
| ^^^^^^^^^^^^^^^^^
error: offset calculation on zero-sized value
--> $DIR/zero_offset.rs:6:9
|
LL | m.sub(0);
| ^^^^^^^^
error: offset calculation on zero-sized value
--> $DIR/zero_offset.rs:7:9
|
LL | m.wrapping_sub(0);
| ^^^^^^^^^^^^^^^^^
error: offset calculation on zero-sized value
--> $DIR/zero_offset.rs:10:9
|
LL | c.offset(0);
| ^^^^^^^^^^^
error: offset calculation on zero-sized value
--> $DIR/zero_offset.rs:11:9
|
LL | c.wrapping_add(0);
| ^^^^^^^^^^^^^^^^^
error: offset calculation on zero-sized value
--> $DIR/zero_offset.rs:12:9
|
LL | c.sub(0);
| ^^^^^^^^
error: offset calculation on zero-sized value
--> $DIR/zero_offset.rs:13:9
|
LL | c.wrapping_sub(0);
| ^^^^^^^^^^^^^^^^^
error: aborting due to 8 previous errors
For more information about this error, try `rustc --explain E0606`.