Skip to content

Commit c8efecf

Browse files
authored
Rollup merge of #95663 - notriddle:notriddle/unsafe-fn-closure, r=compiler-errors
diagnostics: give a special note for unsafe fn / Fn/FnOnce/FnMut Fixes #90073
2 parents d4e56e2 + 44ab1dd commit c8efecf

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

core/src/ops/function.rs

+18
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@
6060
Args = "()",
6161
note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}`"
6262
),
63+
on(
64+
_Self = "unsafe fn",
65+
note = "unsafe function cannot be called generically without an unsafe block",
66+
// SAFETY: tidy is not smart enough to tell that the below unsafe block is a string
67+
label = "call the function in a closure: `|| unsafe {{ /* code */ }}`"
68+
),
6369
message = "expected a `{Fn}<{Args}>` closure, found `{Self}`",
6470
label = "expected an `Fn<{Args}>` closure, found `{Self}`"
6571
)]
@@ -141,6 +147,12 @@ pub trait Fn<Args>: FnMut<Args> {
141147
Args = "()",
142148
note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}`"
143149
),
150+
on(
151+
_Self = "unsafe fn",
152+
note = "unsafe function cannot be called generically without an unsafe block",
153+
// SAFETY: tidy is not smart enough to tell that the below unsafe block is a string
154+
label = "call the function in a closure: `|| unsafe {{ /* code */ }}`"
155+
),
144156
message = "expected a `{FnMut}<{Args}>` closure, found `{Self}`",
145157
label = "expected an `FnMut<{Args}>` closure, found `{Self}`"
146158
)]
@@ -214,6 +226,12 @@ pub trait FnMut<Args>: FnOnce<Args> {
214226
Args = "()",
215227
note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}`"
216228
),
229+
on(
230+
_Self = "unsafe fn",
231+
note = "unsafe function cannot be called generically without an unsafe block",
232+
// SAFETY: tidy is not smart enough to tell that the below unsafe block is a string
233+
label = "call the function in a closure: `|| unsafe {{ /* code */ }}`"
234+
),
217235
message = "expected a `{FnOnce}<{Args}>` closure, found `{Self}`",
218236
label = "expected an `FnOnce<{Args}>` closure, found `{Self}`"
219237
)]

0 commit comments

Comments
 (0)