Skip to content

Commit 8e04961

Browse files
Add ui test for missing_transmute_annotations
1 parent 7976657 commit 8e04961

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+470
-189
lines changed

tests/ui/author/issue_3849.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(dead_code)]
22
#![allow(clippy::zero_ptr)]
33
#![allow(clippy::transmute_ptr_to_ref)]
4-
#![allow(clippy::transmuting_null)]
4+
#![allow(clippy::transmuting_null, clippy::missing_transmute_annotations)]
55

66
pub const ZPTR: *const usize = 0 as *const _;
77

tests/ui/auxiliary/macro_rules.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ macro_rules! macro_with_panic {
5050
panic!()
5151
};
5252
}
53+
54+
#[macro_export]
55+
macro_rules! bad_transmute {
56+
($e:expr) => {
57+
std::mem::transmute($e)
58+
};
59+
}

tests/ui/blocks_in_conditions.fixed

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
//@aux-build:proc_macro_attr.rs
22

33
#![warn(clippy::blocks_in_conditions)]
4-
#![allow(unused, clippy::let_and_return, clippy::needless_if)]
4+
#![allow(
5+
unused,
6+
clippy::let_and_return,
7+
clippy::needless_if,
8+
clippy::missing_transmute_annotations
9+
)]
510
#![warn(clippy::nonminimal_bool)]
611

712
macro_rules! blocky {

tests/ui/blocks_in_conditions.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
//@aux-build:proc_macro_attr.rs
22

33
#![warn(clippy::blocks_in_conditions)]
4-
#![allow(unused, clippy::let_and_return, clippy::needless_if)]
4+
#![allow(
5+
unused,
6+
clippy::let_and_return,
7+
clippy::needless_if,
8+
clippy::missing_transmute_annotations
9+
)]
510
#![warn(clippy::nonminimal_bool)]
611

712
macro_rules! blocky {

tests/ui/blocks_in_conditions.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: in an `if` condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
2-
--> tests/ui/blocks_in_conditions.rs:25:5
2+
--> tests/ui/blocks_in_conditions.rs:30:5
33
|
44
LL | / if {
55
LL | |
@@ -20,13 +20,13 @@ LL ~ }; if res {
2020
|
2121

2222
error: omit braces around single expression condition
23-
--> tests/ui/blocks_in_conditions.rs:37:8
23+
--> tests/ui/blocks_in_conditions.rs:42:8
2424
|
2525
LL | if { true } { 6 } else { 10 }
2626
| ^^^^^^^^ help: try: `true`
2727

2828
error: this boolean expression can be simplified
29-
--> tests/ui/blocks_in_conditions.rs:43:8
29+
--> tests/ui/blocks_in_conditions.rs:48:8
3030
|
3131
LL | if true && x == 3 { 6 } else { 10 }
3232
| ^^^^^^^^^^^^^^ help: try: `x == 3`
@@ -35,7 +35,7 @@ LL | if true && x == 3 { 6 } else { 10 }
3535
= help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]`
3636

3737
error: in a `match` scrutinee, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
38-
--> tests/ui/blocks_in_conditions.rs:70:5
38+
--> tests/ui/blocks_in_conditions.rs:75:5
3939
|
4040
LL | / match {
4141
LL | |

tests/ui/crashes/ice-1782.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(dead_code, unused_variables)]
2-
#![allow(clippy::unnecessary_cast)]
2+
#![allow(clippy::unnecessary_cast, clippy::missing_transmute_annotations)]
33

44
/// Should not trigger an ICE in `SpanlessEq` / `consts::constant`
55
///

tests/ui/eager_transmute.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(rustc_attrs)]
22
#![warn(clippy::eager_transmute)]
3-
#![allow(clippy::transmute_int_to_non_zero)]
3+
#![allow(clippy::transmute_int_to_non_zero, clippy::missing_transmute_annotations)]
44

55
use std::num::NonZeroU8;
66

tests/ui/eager_transmute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(rustc_attrs)]
22
#![warn(clippy::eager_transmute)]
3-
#![allow(clippy::transmute_int_to_non_zero)]
3+
#![allow(clippy::transmute_int_to_non_zero, clippy::missing_transmute_annotations)]
44

55
use std::num::NonZeroU8;
66

tests/ui/missing_const_for_fn/could_be_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![warn(clippy::missing_const_for_fn)]
2-
#![allow(incomplete_features, clippy::let_and_return)]
2+
#![allow(incomplete_features, clippy::let_and_return, clippy::missing_transmute_annotations)]
33
#![feature(const_mut_refs)]
44
#![feature(const_trait_impl)]
55

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//@aux-build:macro_rules.rs
2+
3+
#![warn(clippy::missing_transmute_annotations)]
4+
5+
#[macro_use]
6+
extern crate macro_rules;
7+
8+
macro_rules! local_bad_transmute {
9+
($e:expr) => {
10+
std::mem::transmute::<[u16; 2], i32>($e)
11+
};
12+
}
13+
14+
fn bar(x: i32) -> i32 {
15+
x
16+
}
17+
18+
unsafe fn foo1() -> i32 {
19+
std::mem::transmute::<[u16; 2], i32>([1u16, 2u16])
20+
//~^ ERROR: transmute used without annotations
21+
}
22+
23+
unsafe fn foo2() -> i32 {
24+
std::mem::transmute::<[u16; 2], i32>([1u16, 2u16])
25+
//~^ ERROR: transmute used without annotations
26+
}
27+
28+
unsafe fn foo3() -> i32 {
29+
std::mem::transmute::<[u16; 2], i32>([1u16, 2u16])
30+
//~^ ERROR: transmute used without annotations
31+
}
32+
33+
unsafe fn foo4() -> i32 {
34+
std::mem::transmute::<[u16; 2], i32>([1u16, 2u16])
35+
//~^ ERROR: transmute used without annotations
36+
}
37+
38+
unsafe fn foo5() -> i32 {
39+
let x: i32 = bar(std::mem::transmute::<[u16; 2], i32>([1u16, 2u16]));
40+
//~^ ERROR: transmute used without annotations
41+
bar(std::mem::transmute::<[u16; 2], i32>([1u16, 2u16]))
42+
//~^ ERROR: transmute used without annotations
43+
}
44+
45+
unsafe fn foo6() -> i32 {
46+
local_bad_transmute!([1u16, 2u16])
47+
//~^ ERROR: transmute used without annotations
48+
}
49+
50+
unsafe fn foo7() -> i32 {
51+
// Should not warn.
52+
bad_transmute!([1u16, 2u16])
53+
}
54+
55+
#[repr(i32)]
56+
enum Foo {
57+
A = 0,
58+
}
59+
60+
unsafe fn foo8() -> Foo {
61+
std::mem::transmute::<i32, Foo>(0i32)
62+
//~^ ERROR: transmute used without annotations
63+
}
64+
65+
unsafe fn foo9() -> i32 {
66+
std::mem::transmute::<Foo, i32>(Foo::A)
67+
//~^ ERROR: transmute used without annotations
68+
}
69+
70+
fn main() {
71+
unsafe {
72+
// Should not warn.
73+
std::mem::transmute::<[u16; 2], i32>([1u16, 2u16]);
74+
let x = std::mem::transmute::<[u16; 2], i32>([1u16, 2u16]);
75+
let x: i32 = std::mem::transmute::<[u16; 2], _>([1u16, 2u16]);
76+
let x: i32 = std::mem::transmute::<_, i32>([1u16, 2u16]);
77+
let x: i32 = std::mem::transmute([1u16, 2u16]);
78+
}
79+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//@aux-build:macro_rules.rs
2+
3+
#![warn(clippy::missing_transmute_annotations)]
4+
5+
#[macro_use]
6+
extern crate macro_rules;
7+
8+
macro_rules! local_bad_transmute {
9+
($e:expr) => {
10+
std::mem::transmute($e)
11+
};
12+
}
13+
14+
fn bar(x: i32) -> i32 {
15+
x
16+
}
17+
18+
unsafe fn foo1() -> i32 {
19+
std::mem::transmute([1u16, 2u16])
20+
//~^ ERROR: transmute used without annotations
21+
}
22+
23+
unsafe fn foo2() -> i32 {
24+
std::mem::transmute::<_, _>([1u16, 2u16])
25+
//~^ ERROR: transmute used without annotations
26+
}
27+
28+
unsafe fn foo3() -> i32 {
29+
std::mem::transmute::<_, i32>([1u16, 2u16])
30+
//~^ ERROR: transmute used without annotations
31+
}
32+
33+
unsafe fn foo4() -> i32 {
34+
std::mem::transmute::<[u16; 2], _>([1u16, 2u16])
35+
//~^ ERROR: transmute used without annotations
36+
}
37+
38+
unsafe fn foo5() -> i32 {
39+
let x: i32 = bar(std::mem::transmute::<[u16; 2], _>([1u16, 2u16]));
40+
//~^ ERROR: transmute used without annotations
41+
bar(std::mem::transmute::<[u16; 2], _>([1u16, 2u16]))
42+
//~^ ERROR: transmute used without annotations
43+
}
44+
45+
unsafe fn foo6() -> i32 {
46+
local_bad_transmute!([1u16, 2u16])
47+
//~^ ERROR: transmute used without annotations
48+
}
49+
50+
unsafe fn foo7() -> i32 {
51+
// Should not warn.
52+
bad_transmute!([1u16, 2u16])
53+
}
54+
55+
#[repr(i32)]
56+
enum Foo {
57+
A = 0,
58+
}
59+
60+
unsafe fn foo8() -> Foo {
61+
std::mem::transmute(0i32)
62+
//~^ ERROR: transmute used without annotations
63+
}
64+
65+
unsafe fn foo9() -> i32 {
66+
std::mem::transmute(Foo::A)
67+
//~^ ERROR: transmute used without annotations
68+
}
69+
70+
fn main() {
71+
unsafe {
72+
// Should not warn.
73+
std::mem::transmute::<[u16; 2], i32>([1u16, 2u16]);
74+
let x = std::mem::transmute::<[u16; 2], i32>([1u16, 2u16]);
75+
let x: i32 = std::mem::transmute::<[u16; 2], _>([1u16, 2u16]);
76+
let x: i32 = std::mem::transmute::<_, i32>([1u16, 2u16]);
77+
let x: i32 = std::mem::transmute([1u16, 2u16]);
78+
}
79+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
error: transmute used without annotations
2+
--> tests/ui/missing_transmute_annotations.rs:19:15
3+
|
4+
LL | std::mem::transmute([1u16, 2u16])
5+
| ^^^^^^^^^ help: consider adding missing annotations: `transmute::<[u16; 2], i32>`
6+
|
7+
= note: `-D clippy::missing-transmute-annotations` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::missing_transmute_annotations)]`
9+
10+
error: transmute used without annotations
11+
--> tests/ui/missing_transmute_annotations.rs:24:15
12+
|
13+
LL | std::mem::transmute::<_, _>([1u16, 2u16])
14+
| ^^^^^^^^^^^^^^^^^ help: consider adding missing annotations: `transmute::<[u16; 2], i32>`
15+
16+
error: transmute used without annotations
17+
--> tests/ui/missing_transmute_annotations.rs:29:15
18+
|
19+
LL | std::mem::transmute::<_, i32>([1u16, 2u16])
20+
| ^^^^^^^^^^^^^^^^^^^ help: consider adding missing annotations: `transmute::<[u16; 2], i32>`
21+
22+
error: transmute used without annotations
23+
--> tests/ui/missing_transmute_annotations.rs:34:15
24+
|
25+
LL | 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+
--> tests/ui/missing_transmute_annotations.rs:39:32
30+
|
31+
LL | let x: i32 = bar(std::mem::transmute::<[u16; 2], _>([1u16, 2u16]));
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider adding missing annotations: `transmute::<[u16; 2], i32>`
33+
34+
error: transmute used without annotations
35+
--> tests/ui/missing_transmute_annotations.rs:41:19
36+
|
37+
LL | bar(std::mem::transmute::<[u16; 2], _>([1u16, 2u16]))
38+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider adding missing annotations: `transmute::<[u16; 2], i32>`
39+
40+
error: transmute used without annotations
41+
--> tests/ui/missing_transmute_annotations.rs:10:19
42+
|
43+
LL | std::mem::transmute($e)
44+
| ^^^^^^^^^ help: consider adding missing annotations: `transmute::<[u16; 2], i32>`
45+
...
46+
LL | local_bad_transmute!([1u16, 2u16])
47+
| ---------------------------------- in this macro invocation
48+
|
49+
= note: this error originates in the macro `local_bad_transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
50+
51+
error: transmute used without annotations
52+
--> tests/ui/missing_transmute_annotations.rs:61:15
53+
|
54+
LL | std::mem::transmute(0i32)
55+
| ^^^^^^^^^ help: consider adding missing annotations: `transmute::<i32, Foo>`
56+
57+
error: transmute used without annotations
58+
--> tests/ui/missing_transmute_annotations.rs:66:15
59+
|
60+
LL | std::mem::transmute(Foo::A)
61+
| ^^^^^^^^^ help: consider adding missing annotations: `transmute::<Foo, i32>`
62+
63+
error: aborting due to 9 previous errors
64+

tests/ui/ptr_cast_constness.fixed

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
//@aux-build:proc_macros.rs
22

33
#![warn(clippy::ptr_cast_constness)]
4-
#![allow(clippy::transmute_ptr_to_ref, clippy::unnecessary_cast, unused)]
4+
#![allow(
5+
clippy::transmute_ptr_to_ref,
6+
clippy::unnecessary_cast,
7+
unused,
8+
clippy::missing_transmute_annotations
9+
)]
510

611
extern crate proc_macros;
712
use proc_macros::{external, inline_macros};

tests/ui/ptr_cast_constness.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
//@aux-build:proc_macros.rs
22

33
#![warn(clippy::ptr_cast_constness)]
4-
#![allow(clippy::transmute_ptr_to_ref, clippy::unnecessary_cast, unused)]
4+
#![allow(
5+
clippy::transmute_ptr_to_ref,
6+
clippy::unnecessary_cast,
7+
unused,
8+
clippy::missing_transmute_annotations
9+
)]
510

611
extern crate proc_macros;
712
use proc_macros::{external, inline_macros};

0 commit comments

Comments
 (0)