about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-08-21 01:20:12 +0800
committerGitHub <noreply@github.com>2018-08-21 01:20:12 +0800
commitffde96c201431a36e843ce51fb97e4f003555918 (patch)
tree787d444641aa06fcd999781752f66ae3b1b7a55e /src/libcore
parentfa3d56aca898897abe1d3154cacfa0a3a2619b64 (diff)
parentcea73d6341a136c6f915c45133748ecfbe36729b (diff)
downloadrust-ffde96c201431a36e843ce51fb97e4f003555918.tar.gz
rust-ffde96c201431a36e843ce51fb97e4f003555918.zip
Rollup merge of #53296 - estebank:suggest-closure, r=KodrAus
When closure with no arguments was expected, suggest wrapping

Fix #49694.
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/ops/function.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libcore/ops/function.rs b/src/libcore/ops/function.rs
index d10fcb86b24..3ebd10a9209 100644
--- a/src/libcore/ops/function.rs
+++ b/src/libcore/ops/function.rs
@@ -66,6 +66,11 @@
 #[lang = "fn"]
 #[stable(feature = "rust1", since = "1.0.0")]
 #[rustc_paren_sugar]
+#[rustc_on_unimplemented(
+    on(Args="()", note="wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}"),
+    message="expected a `{Fn}<{Args}>` closure, found `{Self}`",
+    label="expected an `Fn<{Args}>` closure, found `{Self}`",
+)]
 #[fundamental] // so that regex can rely that `&str: !FnMut`
 pub trait Fn<Args> : FnMut<Args> {
     /// Performs the call operation.
@@ -139,6 +144,11 @@ pub trait Fn<Args> : FnMut<Args> {
 #[lang = "fn_mut"]
 #[stable(feature = "rust1", since = "1.0.0")]
 #[rustc_paren_sugar]
+#[rustc_on_unimplemented(
+    on(Args="()", note="wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}"),
+    message="expected a `{FnMut}<{Args}>` closure, found `{Self}`",
+    label="expected an `FnMut<{Args}>` closure, found `{Self}`",
+)]
 #[fundamental] // so that regex can rely that `&str: !FnMut`
 pub trait FnMut<Args> : FnOnce<Args> {
     /// Performs the call operation.
@@ -212,6 +222,11 @@ pub trait FnMut<Args> : FnOnce<Args> {
 #[lang = "fn_once"]
 #[stable(feature = "rust1", since = "1.0.0")]
 #[rustc_paren_sugar]
+#[rustc_on_unimplemented(
+    on(Args="()", note="wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}"),
+    message="expected a `{FnOnce}<{Args}>` closure, found `{Self}`",
+    label="expected an `FnOnce<{Args}>` closure, found `{Self}`",
+)]
 #[fundamental] // so that regex can rely that `&str: !FnMut`
 pub trait FnOnce<Args> {
     /// The returned type after the call operator is used.