diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-04-05 22:58:59 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-05 22:58:59 +0200 |
| commit | 1e555bac14eb5c92507e0aa2c5271990db9e1692 (patch) | |
| tree | dda244fa08c986c0b6e1c254ffe211a08888a843 /library/core/src/ops/function.rs | |
| parent | cbf54fad795bc9bce7905b6deb8dfb3bac4f1e2e (diff) | |
| parent | 6d18fbbc3f1fee9e717ae5f55bd2970d96e2b5cb (diff) | |
| download | rust-1e555bac14eb5c92507e0aa2c5271990db9e1692.tar.gz rust-1e555bac14eb5c92507e0aa2c5271990db9e1692.zip | |
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
Diffstat (limited to 'library/core/src/ops/function.rs')
| -rw-r--r-- | library/core/src/ops/function.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/library/core/src/ops/function.rs b/library/core/src/ops/function.rs index 8383f926435..c5a194b7d0a 100644 --- a/library/core/src/ops/function.rs +++ b/library/core/src/ops/function.rs @@ -60,6 +60,12 @@ Args = "()", note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}`" ), + on( + _Self = "unsafe fn", + note = "unsafe function cannot be called generically without an unsafe block", + // SAFETY: tidy is not smart enough to tell that the below unsafe block is a string + label = "call the function in a closure: `|| unsafe {{ /* code */ }}`" + ), message = "expected a `{Fn}<{Args}>` closure, found `{Self}`", label = "expected an `Fn<{Args}>` closure, found `{Self}`" )] @@ -141,6 +147,12 @@ pub trait Fn<Args>: FnMut<Args> { Args = "()", note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}`" ), + on( + _Self = "unsafe fn", + note = "unsafe function cannot be called generically without an unsafe block", + // SAFETY: tidy is not smart enough to tell that the below unsafe block is a string + label = "call the function in a closure: `|| unsafe {{ /* code */ }}`" + ), message = "expected a `{FnMut}<{Args}>` closure, found `{Self}`", label = "expected an `FnMut<{Args}>` closure, found `{Self}`" )] @@ -214,6 +226,12 @@ pub trait FnMut<Args>: FnOnce<Args> { Args = "()", note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}`" ), + on( + _Self = "unsafe fn", + note = "unsafe function cannot be called generically without an unsafe block", + // SAFETY: tidy is not smart enough to tell that the below unsafe block is a string + label = "call the function in a closure: `|| unsafe {{ /* code */ }}`" + ), message = "expected a `{FnOnce}<{Args}>` closure, found `{Self}`", label = "expected an `FnOnce<{Args}>` closure, found `{Self}`" )] |
