Skip to content

Commit d71caad

Browse files
committed
Add rustc_on_unimplemented message to std::ops::Try
1 parent 8cab2c7 commit d71caad

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/libcore/ops/try.rs

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
/// extracting those success or failure values from an existing instance and
1616
/// creating a new instance from a success or failure value.
1717
#[unstable(feature = "try_trait", issue = "42327")]
18+
#[rustc_on_unimplemented = "the `?` operator can only be used in a function that returns `Result` \
19+
(or another type that implements `std::ops::Try`)"]
1820
pub trait Try {
1921
/// The type of this value when viewed as successful.
2022
#[unstable(feature = "try_trait", issue = "42327")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
std::fs::File::open("foo")?;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0277]: the trait bound `(): std::ops::Try` is not satisfied
2+
--> $DIR/try-operator-on-main.rs:12:5
3+
|
4+
12 | std::fs::File::open("foo")?;
5+
| ---------------------------
6+
| |
7+
| the `?` operator can only be used in a function that returns `Result` (or another type that implements `std::ops::Try`)
8+
| in this macro invocation
9+
|
10+
= help: the trait `std::ops::Try` is not implemented for `()`
11+
= note: required by `std::ops::Try::from_error`
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)