From bec8dbdb602688d6da4f49b7fdd74226f0f9f04c Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 4 Apr 2022 17:37:59 -0700 Subject: diagnostics: give a special note for unsafe fn / Fn/FnOnce/FnMut Fixes #90073 --- library/core/src/ops/function.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'library/core/src/ops/function.rs') diff --git a/library/core/src/ops/function.rs b/library/core/src/ops/function.rs index e5c4798afcb..a7b28471bfe 100644 --- a/library/core/src/ops/function.rs +++ b/library/core/src/ops/function.rs @@ -59,6 +59,10 @@ Args = "()", note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}`" ), + on( + _Self = "unsafe fn", + note = "unsafe functions must be wrapped in closures: `|| unsafe {{ /* code */ }}`" + ), message = "expected a `{Fn}<{Args}>` closure, found `{Self}`", label = "expected an `Fn<{Args}>` closure, found `{Self}`" )] @@ -139,6 +143,10 @@ pub trait Fn: FnMut { Args = "()", note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}`" ), + on( + _Self = "unsafe fn", + note = "unsafe functions must be wrapped in closures: `|| unsafe {{ /* code */ }}`" + ), message = "expected a `{FnMut}<{Args}>` closure, found `{Self}`", label = "expected an `FnMut<{Args}>` closure, found `{Self}`" )] @@ -211,6 +219,10 @@ pub trait FnMut: FnOnce { Args = "()", note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}`" ), + on( + _Self = "unsafe fn", + note = "unsafe functions must be wrapped in closures: `|| unsafe {{ /* code */ }}`" + ), message = "expected a `{FnOnce}<{Args}>` closure, found `{Self}`", label = "expected an `FnOnce<{Args}>` closure, found `{Self}`" )] -- cgit 1.4.1-3-g733a5