Skip to content

Commit 8938bb2

Browse files
committed
clean-up tests
1 parent 49e2f37 commit 8938bb2

File tree

2 files changed

+99
-101
lines changed

2 files changed

+99
-101
lines changed

tests/ui/multiple_unsafe_ops_per_block.rs

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
//@needs-asm-support
22
//@aux-build:proc_macros.rs
3-
#![allow(unused)]
4-
#![allow(deref_nullptr)]
5-
#![allow(clippy::unnecessary_operation)]
6-
#![allow(dropping_copy_types)]
7-
#![allow(clippy::assign_op_pattern)]
3+
#![expect(clippy::unnecessary_operation, dropping_copy_types)]
84
#![warn(clippy::multiple_unsafe_ops_per_block)]
95

106
extern crate proc_macros;
@@ -105,17 +101,17 @@ fn correct3() {
105101
}
106102
}
107103

108-
// tests from the issue (https://github.com/rust-lang/rust-clippy/issues/10064)
109-
110-
unsafe fn read_char_bad(ptr: *const u8) -> char {
111-
unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }
112-
//~^ multiple_unsafe_ops_per_block
113-
}
104+
fn issue10064() {
105+
unsafe fn read_char_bad(ptr: *const u8) -> char {
106+
unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }
107+
//~^ multiple_unsafe_ops_per_block
108+
}
114109

115-
// no lint
116-
unsafe fn read_char_good(ptr: *const u8) -> char {
117-
let int_value = unsafe { *ptr.cast::<u32>() };
118-
unsafe { core::char::from_u32_unchecked(int_value) }
110+
// no lint
111+
unsafe fn read_char_good(ptr: *const u8) -> char {
112+
let int_value = unsafe { *ptr.cast::<u32>() };
113+
unsafe { core::char::from_u32_unchecked(int_value) }
114+
}
119115
}
120116

121117
// no lint
@@ -126,39 +122,41 @@ fn issue10259() {
126122
});
127123
}
128124

129-
fn _fn_ptr(x: unsafe fn()) {
130-
unsafe {
131-
//~^ multiple_unsafe_ops_per_block
132-
x();
133-
x();
125+
fn issue10367() {
126+
fn fn_ptr(x: unsafe fn()) {
127+
unsafe {
128+
//~^ multiple_unsafe_ops_per_block
129+
x();
130+
x();
131+
}
134132
}
135-
}
136133

137-
fn _assoc_const() {
138-
trait X {
139-
const X: unsafe fn();
134+
fn assoc_const() {
135+
trait X {
136+
const X: unsafe fn();
137+
}
138+
fn _f<T: X>() {
139+
unsafe {
140+
//~^ multiple_unsafe_ops_per_block
141+
T::X();
142+
T::X();
143+
}
144+
}
140145
}
141-
fn _f<T: X>() {
146+
147+
fn field_fn_ptr(x: unsafe fn()) {
148+
struct X(unsafe fn());
149+
let x = X(x);
142150
unsafe {
143151
//~^ multiple_unsafe_ops_per_block
144-
T::X();
145-
T::X();
152+
x.0();
153+
x.0();
146154
}
147155
}
148156
}
149157

150-
fn _field_fn_ptr(x: unsafe fn()) {
151-
struct X(unsafe fn());
152-
let x = X(x);
153-
unsafe {
154-
//~^ multiple_unsafe_ops_per_block
155-
x.0();
156-
x.0();
157-
}
158-
}
159-
160-
// await expands to an unsafe block with several operations, but this is fine.: #11312
161-
async fn await_desugaring_silent() {
158+
// await expands to an unsafe block with several operations, but this is fine.
159+
async fn issue11312() {
162160
async fn helper() {}
163161

164162
helper().await;
Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this `unsafe` block contains 2 unsafe operations, expected only one
2-
--> tests/ui/multiple_unsafe_ops_per_block.rs:38:5
2+
--> tests/ui/multiple_unsafe_ops_per_block.rs:34:5
33
|
44
LL | / unsafe {
55
LL | |
@@ -9,20 +9,20 @@ LL | | }
99
| |_____^
1010
|
1111
note: modification of a mutable static occurs here
12-
--> tests/ui/multiple_unsafe_ops_per_block.rs:40:9
12+
--> tests/ui/multiple_unsafe_ops_per_block.rs:36:9
1313
|
1414
LL | STATIC += 1;
1515
| ^^^^^^^^^^^
1616
note: unsafe function call occurs here
17-
--> tests/ui/multiple_unsafe_ops_per_block.rs:41:9
17+
--> tests/ui/multiple_unsafe_ops_per_block.rs:37:9
1818
|
1919
LL | not_very_safe();
2020
| ^^^^^^^^^^^^^^^
2121
= note: `-D clippy::multiple-unsafe-ops-per-block` implied by `-D warnings`
2222
= help: to override `-D warnings` add `#[allow(clippy::multiple_unsafe_ops_per_block)]`
2323

2424
error: this `unsafe` block contains 2 unsafe operations, expected only one
25-
--> tests/ui/multiple_unsafe_ops_per_block.rs:48:5
25+
--> tests/ui/multiple_unsafe_ops_per_block.rs:44:5
2626
|
2727
LL | / unsafe {
2828
LL | |
@@ -32,18 +32,18 @@ LL | | }
3232
| |_____^
3333
|
3434
note: union field access occurs here
35-
--> tests/ui/multiple_unsafe_ops_per_block.rs:50:14
35+
--> tests/ui/multiple_unsafe_ops_per_block.rs:46:14
3636
|
3737
LL | drop(u.u);
3838
| ^^^
3939
note: raw pointer dereference occurs here
40-
--> tests/ui/multiple_unsafe_ops_per_block.rs:51:9
40+
--> tests/ui/multiple_unsafe_ops_per_block.rs:47:9
4141
|
4242
LL | *raw_ptr();
4343
| ^^^^^^^^^^
4444

4545
error: this `unsafe` block contains 3 unsafe operations, expected only one
46-
--> tests/ui/multiple_unsafe_ops_per_block.rs:56:5
46+
--> tests/ui/multiple_unsafe_ops_per_block.rs:52:5
4747
|
4848
LL | / unsafe {
4949
LL | |
@@ -54,23 +54,23 @@ LL | | }
5454
| |_____^
5555
|
5656
note: inline assembly used here
57-
--> tests/ui/multiple_unsafe_ops_per_block.rs:58:9
57+
--> tests/ui/multiple_unsafe_ops_per_block.rs:54:9
5858
|
5959
LL | asm!("nop");
6060
| ^^^^^^^^^^^
6161
note: unsafe method call occurs here
62-
--> tests/ui/multiple_unsafe_ops_per_block.rs:59:9
62+
--> tests/ui/multiple_unsafe_ops_per_block.rs:55:9
6363
|
6464
LL | sample.not_very_safe();
6565
| ^^^^^^^^^^^^^^^^^^^^^^
6666
note: modification of a mutable static occurs here
67-
--> tests/ui/multiple_unsafe_ops_per_block.rs:60:9
67+
--> tests/ui/multiple_unsafe_ops_per_block.rs:56:9
6868
|
6969
LL | STATIC = 0;
7070
| ^^^^^^^^^^
7171

7272
error: this `unsafe` block contains 6 unsafe operations, expected only one
73-
--> tests/ui/multiple_unsafe_ops_per_block.rs:66:5
73+
--> tests/ui/multiple_unsafe_ops_per_block.rs:62:5
7474
|
7575
LL | / unsafe {
7676
LL | |
@@ -82,115 +82,115 @@ LL | | }
8282
| |_____^
8383
|
8484
note: union field access occurs here
85-
--> tests/ui/multiple_unsafe_ops_per_block.rs:68:14
85+
--> tests/ui/multiple_unsafe_ops_per_block.rs:64:14
8686
|
8787
LL | drop(u.u);
8888
| ^^^
8989
note: access of a mutable static occurs here
90-
--> tests/ui/multiple_unsafe_ops_per_block.rs:69:14
90+
--> tests/ui/multiple_unsafe_ops_per_block.rs:65:14
9191
|
9292
LL | drop(STATIC);
9393
| ^^^^^^
9494
note: unsafe method call occurs here
95-
--> tests/ui/multiple_unsafe_ops_per_block.rs:70:9
95+
--> tests/ui/multiple_unsafe_ops_per_block.rs:66:9
9696
|
9797
LL | sample.not_very_safe();
9898
| ^^^^^^^^^^^^^^^^^^^^^^
9999
note: unsafe function call occurs here
100-
--> tests/ui/multiple_unsafe_ops_per_block.rs:71:9
100+
--> tests/ui/multiple_unsafe_ops_per_block.rs:67:9
101101
|
102102
LL | not_very_safe();
103103
| ^^^^^^^^^^^^^^^
104104
note: raw pointer dereference occurs here
105-
--> tests/ui/multiple_unsafe_ops_per_block.rs:72:9
105+
--> tests/ui/multiple_unsafe_ops_per_block.rs:68:9
106106
|
107107
LL | *raw_ptr();
108108
| ^^^^^^^^^^
109109
note: inline assembly used here
110-
--> tests/ui/multiple_unsafe_ops_per_block.rs:73:9
110+
--> tests/ui/multiple_unsafe_ops_per_block.rs:69:9
111111
|
112112
LL | asm!("nop");
113113
| ^^^^^^^^^^^
114114

115115
error: this `unsafe` block contains 2 unsafe operations, expected only one
116-
--> tests/ui/multiple_unsafe_ops_per_block.rs:111:5
116+
--> tests/ui/multiple_unsafe_ops_per_block.rs:106:9
117117
|
118-
LL | unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }
119-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
118+
LL | unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }
119+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
120120
|
121121
note: unsafe function call occurs here
122-
--> tests/ui/multiple_unsafe_ops_per_block.rs:111:14
122+
--> tests/ui/multiple_unsafe_ops_per_block.rs:106:18
123123
|
124-
LL | unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }
125-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
124+
LL | unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }
125+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
126126
note: raw pointer dereference occurs here
127-
--> tests/ui/multiple_unsafe_ops_per_block.rs:111:39
127+
--> tests/ui/multiple_unsafe_ops_per_block.rs:106:43
128128
|
129-
LL | unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }
130-
| ^^^^^^^^^^^^^^^^^^
129+
LL | unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }
130+
| ^^^^^^^^^^^^^^^^^^
131131

132132
error: this `unsafe` block contains 2 unsafe operations, expected only one
133-
--> tests/ui/multiple_unsafe_ops_per_block.rs:130:5
133+
--> tests/ui/multiple_unsafe_ops_per_block.rs:127:9
134134
|
135-
LL | / unsafe {
135+
LL | / unsafe {
136136
LL | |
137-
LL | | x();
138-
LL | | x();
139-
LL | | }
140-
| |_____^
137+
LL | | x();
138+
LL | | x();
139+
LL | | }
140+
| |_________^
141141
|
142142
note: unsafe function call occurs here
143-
--> tests/ui/multiple_unsafe_ops_per_block.rs:132:9
143+
--> tests/ui/multiple_unsafe_ops_per_block.rs:129:13
144144
|
145-
LL | x();
146-
| ^^^
145+
LL | x();
146+
| ^^^
147147
note: unsafe function call occurs here
148-
--> tests/ui/multiple_unsafe_ops_per_block.rs:133:9
148+
--> tests/ui/multiple_unsafe_ops_per_block.rs:130:13
149149
|
150-
LL | x();
151-
| ^^^
150+
LL | x();
151+
| ^^^
152152

153153
error: this `unsafe` block contains 2 unsafe operations, expected only one
154-
--> tests/ui/multiple_unsafe_ops_per_block.rs:142:9
154+
--> tests/ui/multiple_unsafe_ops_per_block.rs:139:13
155155
|
156-
LL | / unsafe {
156+
LL | / unsafe {
157157
LL | |
158-
LL | | T::X();
159-
LL | | T::X();
160-
LL | | }
161-
| |_________^
158+
LL | | T::X();
159+
LL | | T::X();
160+
LL | | }
161+
| |_____________^
162162
|
163163
note: unsafe function call occurs here
164-
--> tests/ui/multiple_unsafe_ops_per_block.rs:144:13
164+
--> tests/ui/multiple_unsafe_ops_per_block.rs:141:17
165165
|
166-
LL | T::X();
167-
| ^^^^^^
166+
LL | T::X();
167+
| ^^^^^^
168168
note: unsafe function call occurs here
169-
--> tests/ui/multiple_unsafe_ops_per_block.rs:145:13
169+
--> tests/ui/multiple_unsafe_ops_per_block.rs:142:17
170170
|
171-
LL | T::X();
172-
| ^^^^^^
171+
LL | T::X();
172+
| ^^^^^^
173173

174174
error: this `unsafe` block contains 2 unsafe operations, expected only one
175-
--> tests/ui/multiple_unsafe_ops_per_block.rs:153:5
175+
--> tests/ui/multiple_unsafe_ops_per_block.rs:150:9
176176
|
177-
LL | / unsafe {
177+
LL | / unsafe {
178178
LL | |
179-
LL | | x.0();
180-
LL | | x.0();
181-
LL | | }
182-
| |_____^
179+
LL | | x.0();
180+
LL | | x.0();
181+
LL | | }
182+
| |_________^
183183
|
184184
note: unsafe function call occurs here
185-
--> tests/ui/multiple_unsafe_ops_per_block.rs:155:9
185+
--> tests/ui/multiple_unsafe_ops_per_block.rs:152:13
186186
|
187-
LL | x.0();
188-
| ^^^^^
187+
LL | x.0();
188+
| ^^^^^
189189
note: unsafe function call occurs here
190-
--> tests/ui/multiple_unsafe_ops_per_block.rs:156:9
190+
--> tests/ui/multiple_unsafe_ops_per_block.rs:153:13
191191
|
192-
LL | x.0();
193-
| ^^^^^
192+
LL | x.0();
193+
| ^^^^^
194194

195195
error: aborting due to 8 previous errors
196196

0 commit comments

Comments
 (0)