Skip to content

Commit a35c78f

Browse files
committed
Extend unused_must_use to cover block exprs
1 parent edb3266 commit a35c78f

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

tests/ui/transmute_ptr_to_ref.fixed

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#![warn(clippy::transmute_ptr_to_ref)]
44
#![allow(clippy::match_single_binding)]
5+
#![allow(unused_must_use)]
56

67
unsafe fn _ptr_to_ref<T, U>(p: *const T, m: *mut T, o: *const U, om: *mut U) {
78
let _: &T = &*p;
@@ -38,7 +39,7 @@ fn _issue1231() {
3839

3940
type Bar<'a> = &'a u8;
4041
let raw = 42 as *const i32;
41-
unsafe { &*(raw as *const u8) };
42+
let _ = unsafe { &*(raw as *const u8) };
4243
}
4344

4445
unsafe fn _issue8924<'a, 'b, 'c>(x: *const &'a u32, y: *const &'b u32) -> &'c &'b u32 {

tests/ui/transmute_ptr_to_ref.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#![warn(clippy::transmute_ptr_to_ref)]
44
#![allow(clippy::match_single_binding)]
5+
#![allow(unused_must_use)]
56

67
unsafe fn _ptr_to_ref<T, U>(p: *const T, m: *mut T, o: *const U, om: *mut U) {
78
let _: &T = std::mem::transmute(p);
@@ -38,7 +39,7 @@ fn _issue1231() {
3839

3940
type Bar<'a> = &'a u8;
4041
let raw = 42 as *const i32;
41-
unsafe { std::mem::transmute::<_, Bar>(raw) };
42+
let _ = unsafe { std::mem::transmute::<_, Bar>(raw) };
4243
}
4344

4445
unsafe fn _issue8924<'a, 'b, 'c>(x: *const &'a u32, y: *const &'b u32) -> &'c &'b u32 {

tests/ui/transmute_ptr_to_ref.stderr

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,133 @@
11
error: transmute from a pointer type (`*const T`) to a reference type (`&T`)
2-
--> $DIR/transmute_ptr_to_ref.rs:7:17
2+
--> $DIR/transmute_ptr_to_ref.rs:8:17
33
|
44
LL | let _: &T = std::mem::transmute(p);
55
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*p`
66
|
77
= note: `-D clippy::transmute-ptr-to-ref` implied by `-D warnings`
88

99
error: transmute from a pointer type (`*mut T`) to a reference type (`&mut T`)
10-
--> $DIR/transmute_ptr_to_ref.rs:10:21
10+
--> $DIR/transmute_ptr_to_ref.rs:11:21
1111
|
1212
LL | let _: &mut T = std::mem::transmute(m);
1313
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *m`
1414

1515
error: transmute from a pointer type (`*mut T`) to a reference type (`&T`)
16-
--> $DIR/transmute_ptr_to_ref.rs:13:17
16+
--> $DIR/transmute_ptr_to_ref.rs:14:17
1717
|
1818
LL | let _: &T = std::mem::transmute(m);
1919
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*m`
2020

2121
error: transmute from a pointer type (`*mut T`) to a reference type (`&mut T`)
22-
--> $DIR/transmute_ptr_to_ref.rs:16:21
22+
--> $DIR/transmute_ptr_to_ref.rs:17:21
2323
|
2424
LL | let _: &mut T = std::mem::transmute(p as *mut T);
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(p as *mut T)`
2626

2727
error: transmute from a pointer type (`*const U`) to a reference type (`&T`)
28-
--> $DIR/transmute_ptr_to_ref.rs:19:17
28+
--> $DIR/transmute_ptr_to_ref.rs:20:17
2929
|
3030
LL | let _: &T = std::mem::transmute(o);
3131
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(o as *const T)`
3232

3333
error: transmute from a pointer type (`*mut U`) to a reference type (`&mut T`)
34-
--> $DIR/transmute_ptr_to_ref.rs:22:21
34+
--> $DIR/transmute_ptr_to_ref.rs:23:21
3535
|
3636
LL | let _: &mut T = std::mem::transmute(om);
3737
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(om as *mut T)`
3838

3939
error: transmute from a pointer type (`*mut U`) to a reference type (`&T`)
40-
--> $DIR/transmute_ptr_to_ref.rs:25:17
40+
--> $DIR/transmute_ptr_to_ref.rs:26:17
4141
|
4242
LL | let _: &T = std::mem::transmute(om);
4343
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(om as *const T)`
4444

4545
error: transmute from a pointer type (`*const i32`) to a reference type (`&_issue1231::Foo<'_, u8>`)
46-
--> $DIR/transmute_ptr_to_ref.rs:35:32
46+
--> $DIR/transmute_ptr_to_ref.rs:36:32
4747
|
4848
LL | let _: &Foo<u8> = unsafe { std::mem::transmute::<_, &Foo<_>>(raw) };
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*raw.cast::<Foo<_>>()`
5050

5151
error: transmute from a pointer type (`*const i32`) to a reference type (`&_issue1231::Foo<'_, &u8>`)
52-
--> $DIR/transmute_ptr_to_ref.rs:37:33
52+
--> $DIR/transmute_ptr_to_ref.rs:38:33
5353
|
5454
LL | let _: &Foo<&u8> = unsafe { std::mem::transmute::<_, &Foo<&_>>(raw) };
5555
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*raw.cast::<Foo<&_>>()`
5656

5757
error: transmute from a pointer type (`*const i32`) to a reference type (`&u8`)
58-
--> $DIR/transmute_ptr_to_ref.rs:41:14
58+
--> $DIR/transmute_ptr_to_ref.rs:42:22
5959
|
60-
LL | unsafe { std::mem::transmute::<_, Bar>(raw) };
61-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const u8)`
60+
LL | let _ = unsafe { std::mem::transmute::<_, Bar>(raw) };
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const u8)`
6262

6363
error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`)
64-
--> $DIR/transmute_ptr_to_ref.rs:46:14
64+
--> $DIR/transmute_ptr_to_ref.rs:47:14
6565
|
6666
LL | 0 => std::mem::transmute(x),
6767
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&u32>()`
6868

6969
error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`)
70-
--> $DIR/transmute_ptr_to_ref.rs:47:14
70+
--> $DIR/transmute_ptr_to_ref.rs:48:14
7171
|
7272
LL | 1 => std::mem::transmute(y),
7373
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*y.cast::<&u32>()`
7474

7575
error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`)
76-
--> $DIR/transmute_ptr_to_ref.rs:48:14
76+
--> $DIR/transmute_ptr_to_ref.rs:49:14
7777
|
7878
LL | 2 => std::mem::transmute::<_, &&'b u32>(x),
7979
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&'b u32>()`
8080

8181
error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`)
82-
--> $DIR/transmute_ptr_to_ref.rs:49:14
82+
--> $DIR/transmute_ptr_to_ref.rs:50:14
8383
|
8484
LL | _ => std::mem::transmute::<_, &&'b u32>(y),
8585
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*y.cast::<&'b u32>()`
8686

8787
error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`)
88-
--> $DIR/transmute_ptr_to_ref.rs:57:19
88+
--> $DIR/transmute_ptr_to_ref.rs:58:19
8989
|
9090
LL | let _: &u32 = std::mem::transmute(a);
9191
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*a`
9292

9393
error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`)
94-
--> $DIR/transmute_ptr_to_ref.rs:58:19
94+
--> $DIR/transmute_ptr_to_ref.rs:59:19
9595
|
9696
LL | let _: &u32 = std::mem::transmute::<_, &u32>(a);
9797
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*a.cast::<u32>()`
9898

9999
error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`)
100-
--> $DIR/transmute_ptr_to_ref.rs:60:14
100+
--> $DIR/transmute_ptr_to_ref.rs:61:14
101101
|
102102
LL | 0 => std::mem::transmute(x),
103103
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&u32>()`
104104

105105
error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`)
106-
--> $DIR/transmute_ptr_to_ref.rs:61:14
106+
--> $DIR/transmute_ptr_to_ref.rs:62:14
107107
|
108108
LL | _ => std::mem::transmute::<_, &&'b u32>(x),
109109
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&'b u32>()`
110110

111111
error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`)
112-
--> $DIR/transmute_ptr_to_ref.rs:69:19
112+
--> $DIR/transmute_ptr_to_ref.rs:70:19
113113
|
114114
LL | let _: &u32 = std::mem::transmute(a);
115115
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*a`
116116

117117
error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`)
118-
--> $DIR/transmute_ptr_to_ref.rs:70:19
118+
--> $DIR/transmute_ptr_to_ref.rs:71:19
119119
|
120120
LL | let _: &u32 = std::mem::transmute::<_, &u32>(a);
121121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(a as *const u32)`
122122

123123
error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`)
124-
--> $DIR/transmute_ptr_to_ref.rs:72:14
124+
--> $DIR/transmute_ptr_to_ref.rs:73:14
125125
|
126126
LL | 0 => std::mem::transmute(x),
127127
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(x as *const () as *const &u32)`
128128

129129
error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`)
130-
--> $DIR/transmute_ptr_to_ref.rs:73:14
130+
--> $DIR/transmute_ptr_to_ref.rs:74:14
131131
|
132132
LL | _ => std::mem::transmute::<_, &&'b u32>(x),
133133
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(x as *const () as *const &'b u32)`

0 commit comments

Comments
 (0)