File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 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`)"]
1820pub trait Try {
1921 /// The type of this value when viewed as successful.
2022 #[ unstable( feature = "try_trait" , issue = "42327" ) ]
Original file line number Diff line number Diff line change 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 number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments