blob: 43eefb97dc28fe011eac212b17f67be9de56415a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
//@ run-rustfix
#![deny(unnecessary_transmutes)]
#![allow(unused_unsafe, unused_imports, unused_variables, unused_parens)]
use std::mem::transmute;
pub fn bytes_at_home(x: u32) -> [u8; 4] {
unsafe { transmute(x) }
//~^ ERROR
}
pub const fn intinator_const(from: bool) -> u8 {
unsafe { transmute(from) }
//~^ ERROR
}
pub static X: u8 = unsafe { transmute(true) };
//~^ ERROR
pub const Y: u8 = unsafe { transmute(true) };
//~^ ERROR
pub struct Z {}
impl Z {
pub const fn intinator_assoc(x: bool) -> u8 {
unsafe { transmute(x) }
//~^ ERROR
}
}
fn main() {
const { unsafe { transmute::<_, u8>(true) } };
//~^ ERROR
unsafe {
let x: u16 = transmute(*b"01");
//~^ ERROR
let x: [u8; 2] = transmute(x);
//~^ ERROR
let x: u32 = transmute(*b"0123");
//~^ ERROR
let x: [u8; 4] = transmute(x);
//~^ ERROR
let x: u64 = transmute(*b"feriscat");
//~^ ERROR
let x: [u8; 8] = transmute(x);
//~^ ERROR
let y: i16 = transmute(*b"01");
//~^ ERROR
let y: [u8; 2] = transmute(y);
//~^ ERROR
let y: i32 = transmute(*b"0123");
//~^ ERROR
let y: [u8; 4] = transmute(y);
//~^ ERROR
let y: i64 = transmute(*b"feriscat");
//~^ ERROR
let y: [u8; 8] = transmute(y);
//~^ ERROR
let z: f32 = transmute(*b"0123");
//~^ ERROR
let z: [u8; 4] = transmute(z);
//~^ ERROR
let z: f64 = transmute(*b"feriscat");
//~^ ERROR
let z: [u8; 8] = transmute(z);
//~^ ERROR
let y: u32 = transmute('🦀');
//~^ ERROR
let y: char = transmute(y);
//~^ ERROR
let y: i32 = transmute('🐱');
//~^ ERROR
let y: char = transmute(y);
//~^ ERROR
let x: u16 = transmute(8i16);
//~^ ERROR
let x: i16 = transmute(x);
//~^ ERROR
let x: u32 = transmute(4i32);
//~^ ERROR
let x: i32 = transmute(x);
//~^ ERROR
let x: u64 = transmute(7i64);
//~^ ERROR
let x: i64 = transmute(x);
//~^ ERROR
let y: f32 = transmute(1u32);
//~^ ERROR
let y: u32 = transmute(y);
//~^ ERROR
let y: f64 = transmute(3u64);
//~^ ERROR
let y: u64 = transmute(2.0);
//~^ ERROR
let y: f64 = transmute(1i64);
//~^ ERROR
let y: i64 = transmute(1f64);
//~^ ERROR
let z: bool = transmute(1u8);
// clippy
let z: u8 = transmute(z);
//~^ ERROR
let z: bool = transmute(1i8);
// clippy
let z: i8 = transmute(z);
//~^ ERROR
}
}
|