Skip to content

Commit

Permalink
add allow unused_unsafe and allow dead_code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan1729 committed Aug 9, 2020
1 parent bc8d32d commit 873e5f5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
3 changes: 2 additions & 1 deletion tests/ui/transmutes_expressible_as_ptr_casts.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
// would otherwise be responsible for
#![warn(clippy::useless_transmute)]
#![warn(clippy::transmute_ptr_to_ptr)]
#![allow(unused_unsafe)]
#![allow(dead_code)]

use std::mem::{size_of, transmute};

// rustc_typeck::check::cast contains documentation about when a cast `e as U` is
// valid, which we quote from below.

fn main() {
// We should see an error message for each transmute, and no error messages for
// the casts, since the casts are the recommended fixes.
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/transmutes_expressible_as_ptr_casts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
// would otherwise be responsible for
#![warn(clippy::useless_transmute)]
#![warn(clippy::transmute_ptr_to_ptr)]
#![allow(unused_unsafe)]
#![allow(dead_code)]

use std::mem::{size_of, transmute};

// rustc_typeck::check::cast contains documentation about when a cast `e as U` is
// valid, which we quote from below.

fn main() {
// We should see an error message for each transmute, and no error messages for
// the casts, since the casts are the recommended fixes.
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/transmutes_expressible_as_ptr_casts.stderr
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
error: transmute from an integer to a pointer
--> $DIR/transmutes_expressible_as_ptr_casts.rs:19:9
--> $DIR/transmutes_expressible_as_ptr_casts.rs:20:9
|
LL | transmute::<usize, *const i32>(usize::MAX)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `usize::MAX as *const i32`
|
= note: `-D clippy::useless-transmute` implied by `-D warnings`

error: transmute from a pointer to a pointer
--> $DIR/transmutes_expressible_as_ptr_casts.rs:25:9
--> $DIR/transmutes_expressible_as_ptr_casts.rs:26:9
|
LL | transmute::<*const i32, *const i8>(ptr_i32)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as *const i8`
|
= note: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings`

error: transmute from a pointer to a pointer
--> $DIR/transmutes_expressible_as_ptr_casts.rs:33:9
--> $DIR/transmutes_expressible_as_ptr_casts.rs:34:9
|
LL | transmute::<*const [i32], *const [u16]>(slice_ptr)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `slice_ptr as *const [u16]`

error: transmute from `*const i32` to `usize` which could be expressed as a pointer cast instead
--> $DIR/transmutes_expressible_as_ptr_casts.rs:41:9
--> $DIR/transmutes_expressible_as_ptr_casts.rs:42:9
|
LL | transmute::<*const i32, usize>(ptr_i32)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as usize`
|
= note: `-D clippy::transmutes-expressible-as-ptr-casts` implied by `-D warnings`

error: transmute from a reference to a pointer
--> $DIR/transmutes_expressible_as_ptr_casts.rs:49:9
--> $DIR/transmutes_expressible_as_ptr_casts.rs:50:9
|
LL | transmute::<&[i32; 4], *const [i32; 4]>(array_ref)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `array_ref as *const [i32; 4]`

error: transmute from `fn(usize) -> u8 {main::foo}` to `*const usize` which could be expressed as a pointer cast instead
--> $DIR/transmutes_expressible_as_ptr_casts.rs:57:9
--> $DIR/transmutes_expressible_as_ptr_casts.rs:58:9
|
LL | transmute::<fn(usize) -> u8, *const usize>(foo)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `foo as *const usize`

error: transmute from `fn(usize) -> u8 {main::foo}` to `usize` which could be expressed as a pointer cast instead
--> $DIR/transmutes_expressible_as_ptr_casts.rs:63:9
--> $DIR/transmutes_expressible_as_ptr_casts.rs:64:9
|
LL | transmute::<fn(usize) -> u8, usize>(foo)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `foo as usize`

error: transmute from a reference to a pointer
--> $DIR/transmutes_expressible_as_ptr_casts.rs:76:14
--> $DIR/transmutes_expressible_as_ptr_casts.rs:77:14
|
LL | unsafe { transmute::<&[i32; 1], *const u8>(in_param) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `in_param as *const [i32; 1] as *const u8`
Expand Down

0 comments on commit 873e5f5

Please sign in to comment.