Skip to content

Commit 0ea973e

Browse files
committed
Fix adjustments
1 parent 62589a2 commit 0ea973e

File tree

3 files changed

+53
-24
lines changed

3 files changed

+53
-24
lines changed

clippy_lints/src/multiple_unsafe_ops_per_block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ fn collect_unsafe_exprs<'tcx>(
130130
unsafe_ops.push(("access of a mutable static occurs here", expr.span));
131131
},
132132

133-
ExprKind::Unary(UnOp::Deref, e) if cx.typeck_results().expr_ty_adjusted(e).is_raw_ptr() => {
133+
ExprKind::Unary(UnOp::Deref, e) if cx.typeck_results().expr_ty(e).is_raw_ptr() => {
134134
unsafe_ops.push(("raw pointer dereference occurs here", expr.span));
135135
},
136136

137137
ExprKind::Call(path_expr, _) => {
138-
let sig = match *cx.typeck_results().expr_ty(path_expr).kind() {
138+
let sig = match *cx.typeck_results().expr_ty_adjusted(path_expr).kind() {
139139
ty::FnDef(id, _) => cx.tcx.fn_sig(id).skip_binder(),
140140
ty::FnPtr(sig_tys, hdr) => sig_tys.with(hdr),
141141
_ => return Continue(Descend::Yes),

tests/ui/multiple_unsafe_ops_per_block.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ fn correct3() {
105105
}
106106
}
107107

108+
fn with_adjustment(f: &unsafe fn()) {
109+
unsafe {
110+
//~^ multiple_unsafe_ops_per_block
111+
f();
112+
f();
113+
}
114+
}
115+
108116
fn issue10064() {
109117
unsafe fn read_char_bad(ptr: *const u8) -> char {
110118
unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }

tests/ui/multiple_unsafe_ops_per_block.stderr

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -113,24 +113,45 @@ 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:110:9
116+
--> tests/ui/multiple_unsafe_ops_per_block.rs:109:5
117+
|
118+
LL | / unsafe {
119+
LL | |
120+
LL | | f();
121+
LL | | f();
122+
LL | | }
123+
| |_____^
124+
|
125+
note: unsafe function call occurs here
126+
--> tests/ui/multiple_unsafe_ops_per_block.rs:111:9
127+
|
128+
LL | f();
129+
| ^^^
130+
note: unsafe function call occurs here
131+
--> tests/ui/multiple_unsafe_ops_per_block.rs:112:9
132+
|
133+
LL | f();
134+
| ^^^
135+
136+
error: this `unsafe` block contains 2 unsafe operations, expected only one
137+
--> tests/ui/multiple_unsafe_ops_per_block.rs:118:9
117138
|
118139
LL | unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }
119140
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
120141
|
121142
note: unsafe function call occurs here
122-
--> tests/ui/multiple_unsafe_ops_per_block.rs:110:18
143+
--> tests/ui/multiple_unsafe_ops_per_block.rs:118:18
123144
|
124145
LL | unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }
125146
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
126147
note: raw pointer dereference occurs here
127-
--> tests/ui/multiple_unsafe_ops_per_block.rs:110:43
148+
--> tests/ui/multiple_unsafe_ops_per_block.rs:118:43
128149
|
129150
LL | unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }
130151
| ^^^^^^^^^^^^^^^^^^
131152

132153
error: this `unsafe` block contains 2 unsafe operations, expected only one
133-
--> tests/ui/multiple_unsafe_ops_per_block.rs:131:9
154+
--> tests/ui/multiple_unsafe_ops_per_block.rs:139:9
134155
|
135156
LL | / unsafe {
136157
LL | |
@@ -140,18 +161,18 @@ LL | | }
140161
| |_________^
141162
|
142163
note: unsafe function call occurs here
143-
--> tests/ui/multiple_unsafe_ops_per_block.rs:133:13
164+
--> tests/ui/multiple_unsafe_ops_per_block.rs:141:13
144165
|
145166
LL | x();
146167
| ^^^
147168
note: unsafe function call occurs here
148-
--> tests/ui/multiple_unsafe_ops_per_block.rs:134:13
169+
--> tests/ui/multiple_unsafe_ops_per_block.rs:142:13
149170
|
150171
LL | x();
151172
| ^^^
152173

153174
error: this `unsafe` block contains 2 unsafe operations, expected only one
154-
--> tests/ui/multiple_unsafe_ops_per_block.rs:143:13
175+
--> tests/ui/multiple_unsafe_ops_per_block.rs:151:13
155176
|
156177
LL | / unsafe {
157178
LL | |
@@ -161,18 +182,18 @@ LL | | }
161182
| |_____________^
162183
|
163184
note: unsafe function call occurs here
164-
--> tests/ui/multiple_unsafe_ops_per_block.rs:145:17
185+
--> tests/ui/multiple_unsafe_ops_per_block.rs:153:17
165186
|
166187
LL | T::X();
167188
| ^^^^^^
168189
note: unsafe function call occurs here
169-
--> tests/ui/multiple_unsafe_ops_per_block.rs:146:17
190+
--> tests/ui/multiple_unsafe_ops_per_block.rs:154:17
170191
|
171192
LL | T::X();
172193
| ^^^^^^
173194

174195
error: this `unsafe` block contains 2 unsafe operations, expected only one
175-
--> tests/ui/multiple_unsafe_ops_per_block.rs:154:9
196+
--> tests/ui/multiple_unsafe_ops_per_block.rs:162:9
176197
|
177198
LL | / unsafe {
178199
LL | |
@@ -182,18 +203,18 @@ LL | | }
182203
| |_________^
183204
|
184205
note: unsafe function call occurs here
185-
--> tests/ui/multiple_unsafe_ops_per_block.rs:156:13
206+
--> tests/ui/multiple_unsafe_ops_per_block.rs:164:13
186207
|
187208
LL | x.0();
188209
| ^^^^^
189210
note: unsafe function call occurs here
190-
--> tests/ui/multiple_unsafe_ops_per_block.rs:157:13
211+
--> tests/ui/multiple_unsafe_ops_per_block.rs:165:13
191212
|
192213
LL | x.0();
193214
| ^^^^^
194215

195216
error: this `unsafe` block contains 2 unsafe operations, expected only one
196-
--> tests/ui/multiple_unsafe_ops_per_block.rs:184:5
217+
--> tests/ui/multiple_unsafe_ops_per_block.rs:192:5
197218
|
198219
LL | / unsafe {
199220
LL | |
@@ -204,18 +225,18 @@ LL | | }
204225
| |_____^
205226
|
206227
note: unsafe function call occurs here
207-
--> tests/ui/multiple_unsafe_ops_per_block.rs:186:9
228+
--> tests/ui/multiple_unsafe_ops_per_block.rs:194:9
208229
|
209230
LL | not_very_safe();
210231
| ^^^^^^^^^^^^^^^
211232
note: modification of a mutable static occurs here
212-
--> tests/ui/multiple_unsafe_ops_per_block.rs:187:9
233+
--> tests/ui/multiple_unsafe_ops_per_block.rs:195:9
213234
|
214235
LL | STATIC += 1;
215236
| ^^^^^^^^^^^
216237

217238
error: this `unsafe` block contains 2 unsafe operations, expected only one
218-
--> tests/ui/multiple_unsafe_ops_per_block.rs:199:5
239+
--> tests/ui/multiple_unsafe_ops_per_block.rs:207:5
219240
|
220241
LL | / unsafe {
221242
LL | |
@@ -225,18 +246,18 @@ LL | | }
225246
| |_____^
226247
|
227248
note: unsafe function call occurs here
228-
--> tests/ui/multiple_unsafe_ops_per_block.rs:201:9
249+
--> tests/ui/multiple_unsafe_ops_per_block.rs:209:9
229250
|
230251
LL | not_very_safe();
231252
| ^^^^^^^^^^^^^^^
232253
note: unsafe function call occurs here
233-
--> tests/ui/multiple_unsafe_ops_per_block.rs:202:9
254+
--> tests/ui/multiple_unsafe_ops_per_block.rs:210:9
234255
|
235256
LL | foo_unchecked().await;
236257
| ^^^^^^^^^^^^^^^
237258

238259
error: this `unsafe` block contains 2 unsafe operations, expected only one
239-
--> tests/ui/multiple_unsafe_ops_per_block.rs:206:5
260+
--> tests/ui/multiple_unsafe_ops_per_block.rs:214:5
240261
|
241262
LL | / unsafe {
242263
LL | |
@@ -245,15 +266,15 @@ LL | | }
245266
| |_____^
246267
|
247268
note: unsafe method call occurs here
248-
--> tests/ui/multiple_unsafe_ops_per_block.rs:208:9
269+
--> tests/ui/multiple_unsafe_ops_per_block.rs:216:9
249270
|
250271
LL | Some(foo_unchecked()).unwrap_unchecked().await;
251272
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
252273
note: unsafe function call occurs here
253-
--> tests/ui/multiple_unsafe_ops_per_block.rs:208:14
274+
--> tests/ui/multiple_unsafe_ops_per_block.rs:216:14
254275
|
255276
LL | Some(foo_unchecked()).unwrap_unchecked().await;
256277
| ^^^^^^^^^^^^^^^
257278

258-
error: aborting due to 11 previous errors
279+
error: aborting due to 12 previous errors
259280

0 commit comments

Comments
 (0)