Skip to content

Commit f9fdb10

Browse files
Add ui test for missing_transmute_annotation
1 parent b0f8d29 commit f9fdb10

3 files changed

+90
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![warn(clippy::missing_transmute_annotations)]
2+
3+
macro_rules! bad_transmute {
4+
($e:expr) => {
5+
std::mem::transmute::<[u16; 2], i32>($e)
6+
}
7+
}
8+
9+
fn main() {
10+
unsafe {
11+
let x: i32 = std::mem::transmute::<[u16; 2], i32>([1u16, 2u16]);
12+
//~^ ERROR: transmute used without annotations
13+
let x: i32 = std::mem::transmute::<[u16; 2], i32>([1u16, 2u16]);
14+
//~^ ERROR: transmute used without annotations
15+
let x = std::mem::transmute::<[u16; 2], i32>([1u16, 2u16]);
16+
//~^ ERROR: transmute used without annotations
17+
let x: i32 = std::mem::transmute::<[u16; 2], i32>([1u16, 2u16]);
18+
//~^ ERROR: transmute used without annotations
19+
let x: i32 = bad_transmute!([1u16, 2u16]);
20+
//~^ ERROR: transmute used without annotations
21+
22+
// Should not warn.
23+
let x = std::mem::transmute::<[u16; 2], i32>([1u16, 2u16]);
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![warn(clippy::missing_transmute_annotation)]
2+
3+
macro_rules! bad_transmute {
4+
($e:expr) => {
5+
std::mem::transmute($e)
6+
};
7+
}
8+
9+
fn main() {
10+
unsafe {
11+
let x: i32 = std::mem::transmute([1u16, 2u16]);
12+
//~^ ERROR: transmute used without annotations
13+
let x: i32 = std::mem::transmute::<_, _>([1u16, 2u16]);
14+
//~^ ERROR: transmute used without annotations
15+
let x = std::mem::transmute::<_, i32>([1u16, 2u16]);
16+
//~^ ERROR: transmute used without annotations
17+
let x: i32 = std::mem::transmute::<[u16; 2], _>([1u16, 2u16]);
18+
//~^ ERROR: transmute used without annotations
19+
let x: i32 = bad_transmute!([1u16, 2u16]);
20+
//~^ ERROR: transmute used without annotations
21+
22+
// Should not warn.
23+
let x = std::mem::transmute::<[u16; 2], i32>([1u16, 2u16]);
24+
}
25+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
error: transmute used without annotations
2+
--> $DIR/missing_transmute_annotations.rs:11:32
3+
|
4+
LL | let x: i32 = std::mem::transmute([1u16, 2u16]);
5+
| ^^^^^^^^^ help: consider adding missing annotations: `transmute::<[u16; 2], i32>`
6+
|
7+
= note: `-D clippy::missing-transmute-annotation` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::missing_transmute_annotation)]`
9+
10+
error: transmute used without annotations
11+
--> $DIR/missing_transmute_annotations.rs:13:32
12+
|
13+
LL | let x: i32 = std::mem::transmute::<_, _>([1u16, 2u16]);
14+
| ^^^^^^^^^^^^^^^^^ help: consider adding missing annotations: `transmute::<[u16; 2], i32>`
15+
16+
error: transmute used without annotations
17+
--> $DIR/missing_transmute_annotations.rs:15:27
18+
|
19+
LL | let x = std::mem::transmute::<_, i32>([1u16, 2u16]);
20+
| ^^^^^^^^^^^^^^^^^^^ help: consider adding missing annotations: `transmute::<[u16; 2], i32>`
21+
22+
error: transmute used without annotations
23+
--> $DIR/missing_transmute_annotations.rs:17:32
24+
|
25+
LL | let x: i32 = std::mem::transmute::<[u16; 2], _>([1u16, 2u16]);
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider adding missing annotations: `transmute::<[u16; 2], i32>`
27+
28+
error: transmute used without annotations
29+
--> $DIR/missing_transmute_annotations.rs:5:19
30+
|
31+
LL | std::mem::transmute($e)
32+
| ^^^^^^^^^ help: consider adding missing annotations: `transmute::<[u16; 2], i32>`
33+
...
34+
LL | let x: i32 = bad_transmute!([1u16, 2u16]);
35+
| ---------------------------- in this macro invocation
36+
|
37+
= note: this error originates in the macro `bad_transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
38+
39+
error: aborting due to 5 previous errors
40+

0 commit comments

Comments
 (0)