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+
}

0 commit comments

Comments
 (0)