Skip to content

Commit f485ec8

Browse files
committed
diagnostics: tweak error message to give more rationale to unsafe Fn
1 parent 478318a commit f485ec8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

core/src/ops/function.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@
6161
),
6262
on(
6363
_Self = "unsafe fn",
64+
note = "unsafe function cannot be called generically without an unsafe block",
6465
// SAFETY: tidy is not smart enough to tell that the below unsafe block is a string
65-
note = "unsafe functions must be wrapped in closures: `|| unsafe {{ /* code */ }}`"
66+
label = "call the function in a closure: `|| unsafe {{ /* code */ }}`"
6667
),
6768
message = "expected a `{Fn}<{Args}>` closure, found `{Self}`",
6869
label = "expected an `Fn<{Args}>` closure, found `{Self}`"
@@ -146,8 +147,9 @@ pub trait Fn<Args>: FnMut<Args> {
146147
),
147148
on(
148149
_Self = "unsafe fn",
150+
note = "unsafe function cannot be called generically without an unsafe block",
149151
// SAFETY: tidy is not smart enough to tell that the below unsafe block is a string
150-
note = "unsafe functions must be wrapped in closures: `|| unsafe {{ /* code */ }}`"
152+
label = "call the function in a closure: `|| unsafe {{ /* code */ }}`"
151153
),
152154
message = "expected a `{FnMut}<{Args}>` closure, found `{Self}`",
153155
label = "expected an `FnMut<{Args}>` closure, found `{Self}`"
@@ -223,8 +225,9 @@ pub trait FnMut<Args>: FnOnce<Args> {
223225
),
224226
on(
225227
_Self = "unsafe fn",
228+
note = "unsafe function cannot be called generically without an unsafe block",
226229
// SAFETY: tidy is not smart enough to tell that the below unsafe block is a string
227-
note = "unsafe functions must be wrapped in closures: `|| unsafe {{ /* code */ }}`"
230+
label = "call the function in a closure: `|| unsafe {{ /* code */ }}`"
228231
),
229232
message = "expected a `{FnOnce}<{Args}>` closure, found `{Self}`",
230233
label = "expected an `FnOnce<{Args}>` closure, found `{Self}`"

0 commit comments

Comments
 (0)