about summary refs log tree commit diff
path: root/src/libcore/ops
diff options
context:
space:
mode:
authorTyler Mandry <tmandry@gmail.com>2019-11-01 11:20:14 -0700
committerGitHub <noreply@github.com>2019-11-01 11:20:14 -0700
commitd75338e6301ea842bc3dd92e3793626b20346aaf (patch)
tree0c9c12126d0750a551a8d6d36e30e7f331408345 /src/libcore/ops
parent48a9f59ae7e1444ee38fb5afa849daacfb7d02e7 (diff)
parentd7869ec02281be58ed3857b545f258b81a6adb09 (diff)
Rollup merge of #65902 - gilescope:issue62570, r=estebank
Make ItemContext available for better diagnositcs

Fix #62570
Diffstat (limited to 'src/libcore/ops')
-rw-r--r--src/libcore/ops/try.rs17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/libcore/ops/try.rs b/src/libcore/ops/try.rs
index 76fec1020f1..e8f35f8cf24 100644
--- a/src/libcore/ops/try.rs
+++ b/src/libcore/ops/try.rs
@@ -5,7 +5,7 @@
 /// extracting those success or failure values from an existing instance and
 /// creating a new instance from a success or failure value.
 #[unstable(feature = "try_trait", issue = "42327")]
-#[rustc_on_unimplemented(
+#[cfg_attr(bootstrap, rustc_on_unimplemented(
    on(all(
        any(from_method="from_error", from_method="from_ok"),
        from_desugaring="QuestionMark"),
@@ -17,7 +17,20 @@
       message="the `?` operator can only be applied to values \
                that implement `{Try}`",
       label="the `?` operator cannot be applied to type `{Self}`")
-)]
+))]
+#[cfg_attr(not(bootstrap), rustc_on_unimplemented(
+on(all(
+any(from_method="from_error", from_method="from_ok"),
+from_desugaring="QuestionMark"),
+message="the `?` operator can only be used in {ItemContext} \
+               that returns `Result` or `Option` \
+               (or another type that implements `{Try}`)",
+label="cannot use the `?` operator in {ItemContext} that returns `{Self}`"),
+on(all(from_method="into_result", from_desugaring="QuestionMark"),
+message="the `?` operator can only be applied to values \
+               that implement `{Try}`",
+label="the `?` operator cannot be applied to type `{Self}`")
+))]
 #[doc(alias = "?")]
 pub trait Try {
     /// The type of this value when viewed as successful.