Skip to content

Commit 71d0145

Browse files
committed
diagnostics: give a special note for unsafe fn / Fn/FnOnce/FnMut
Fixes #90073
1 parent 2382259 commit 71d0145

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

core/src/ops/function.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
Args = "()",
6060
note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}`"
6161
),
62+
on(
63+
_Self = "unsafe fn",
64+
note = "unsafe functions must be wrapped in closures: `|| unsafe {{ /* code */ }}`"
65+
),
6266
message = "expected a `{Fn}<{Args}>` closure, found `{Self}`",
6367
label = "expected an `Fn<{Args}>` closure, found `{Self}`"
6468
)]
@@ -139,6 +143,10 @@ pub trait Fn<Args>: FnMut<Args> {
139143
Args = "()",
140144
note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}`"
141145
),
146+
on(
147+
_Self = "unsafe fn",
148+
note = "unsafe functions must be wrapped in closures: `|| unsafe {{ /* code */ }}`"
149+
),
142150
message = "expected a `{FnMut}<{Args}>` closure, found `{Self}`",
143151
label = "expected an `FnMut<{Args}>` closure, found `{Self}`"
144152
)]
@@ -211,6 +219,10 @@ pub trait FnMut<Args>: FnOnce<Args> {
211219
Args = "()",
212220
note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}`"
213221
),
222+
on(
223+
_Self = "unsafe fn",
224+
note = "unsafe functions must be wrapped in closures: `|| unsafe {{ /* code */ }}`"
225+
),
214226
message = "expected a `{FnOnce}<{Args}>` closure, found `{Self}`",
215227
label = "expected an `FnOnce<{Args}>` closure, found `{Self}`"
216228
)]

0 commit comments

Comments
 (0)