Skip to content

Commit 31298f9

Browse files
committed
Suggest {to,from}_ne_bytes for transmutations between arrays and integers, etc
1 parent c20616c commit 31298f9

File tree

8 files changed

+8
-1
lines changed

8 files changed

+8
-1
lines changed

tests/fail/validity/invalid_bool.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(unnecessary_transmutes)]
12
fn main() {
23
let _b = unsafe { std::mem::transmute::<u8, bool>(2) }; //~ ERROR: expected a boolean
34
}

tests/fail/validity/invalid_bool_op.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Make sure we find these even with many checks disabled.
33
//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
44

5+
#![allow(unnecessary_transmutes)]
56
fn main() {
67
let b = unsafe { std::mem::transmute::<u8, bool>(2) };
78
let _x = b == std::hint::black_box(true); //~ ERROR: interpreting an invalid 8-bit value as a bool

tests/fail/validity/invalid_char.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(unnecessary_transmutes)]
12
fn main() {
23
assert!(std::char::from_u32(-1_i32 as u32).is_none());
34
let _val = match unsafe { std::mem::transmute::<i32, char>(-1) } {

tests/fail/validity/invalid_char_op.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Make sure we find these even with many checks disabled.
33
//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
44

5+
#![allow(unnecessary_transmutes)]
56
fn main() {
67
let c = 0xFFFFFFu32;
78
assert!(std::char::from_u32(c).is_none());

tests/pass/float.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(f16)]
77
#![allow(arithmetic_overflow)]
88
#![allow(internal_features)]
9+
#![allow(unnecessary_transmutes)]
910

1011
use std::any::type_name;
1112
use std::cmp::min;

tests/pass/issues/issue-miri-184.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(unnecessary_transmutes)]
12
pub fn main() {
23
let bytes: [u8; 8] = unsafe { ::std::mem::transmute(0u64) };
34
let _val: &[u8] = &bytes;

tests/pass/shims/x86/intrinsics-x86-gfni.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ unsafe fn load_m256i_word<T>(data: &[T], word_index: usize) -> __m256i {
368368
#[target_feature(enable = "avx512f")]
369369
unsafe fn load_m512i_word<T>(data: &[T], word_index: usize) -> __m512i {
370370
let byte_offset = word_index * 64 / size_of::<T>();
371-
let pointer = data.as_ptr().add(byte_offset) as *const i32;
371+
let pointer = data.as_ptr().add(byte_offset) as *const __m512i;
372372
_mm512_loadu_si512(black_box(pointer))
373373
}
374374

tests/pass/shims/x86/intrinsics-x86-sse.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// We're testing x86 target specific features
22
//@only-target: x86_64 i686
3+
#![allow(unnecessary_transmutes)]
34

45
#[cfg(target_arch = "x86")]
56
use std::arch::x86::*;

0 commit comments

Comments
 (0)