about summary refs log tree commit diff
path: root/src/libcore/ops
diff options
context:
space:
mode:
authorGiles Cope <gilescope@gmail.com>2019-10-28 19:04:15 +0000
committerGiles Cope <gilescope@gmail.com>2019-10-30 06:12:49 +0000
commitd7869ec02281be58ed3857b545f258b81a6adb09 (patch)
treeb6a5197feb9f41a311bb1e3935d49d4417811899 /src/libcore/ops
parent3fa9554d77960627cb2c983470bceacfeeb486b0 (diff)
Make ItemContext available for better diagnositcs.
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.