-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rename the if_ok!
macro
#12037
Comments
I think that The semantics of The semantics of the proposed I don't think it's important for the semantics to be identical; new Rust users know that Rust doesn't have exceptions, and the analogy is strong enough to put them on the right path. |
Why I don't like Why I don't like |
Here's @alexcrichton's example written with
|
We could rename |
FWIW: |
I think I like |
|
The example with
|
My biggest complaint with Of the 3, I think fn foo() -> io::IoResult<()> {
result!(some_function());
let bar = result!(some_function());
if result!(some_function()) {
// ...
}
match result!(some_function()) {
// ...
}
} It's not great either, but it doesn't have any preexisting semantic baggage, and for |
. |
|
result!
2014年2月9日 上午1:29于 "Adrien Tétar" notifications@github.com写道:
|
The goals that this macro has are twofold:
The reason I like try! is that it balances those two needs better than the other options on offer:
My concerns with the other options:
To me, |
|
The macro could be explained like in "call function X, check the result value and either on success use the value in place or return from the calling function". Try and then what? In case of an error:
|
I like if_ok! because it resembles the pattern you would have matched against. How about if_none! if the error condition is wrapped in Option? Support for monads may be an interesting way to solve this too. Eric
|
Let's go with |
This "bubble up an error" macro was originally named if_ok! in order to get it landed, but after the fact it was discovered that this name is not exactly desirable. The name `if_ok!` isn't immediately clear that is has much to do with error handling, and it doesn't look fantastic in all contexts (if if_ok!(...) {}). In general, the agreed opinion about `if_ok!` is that is came in as subpar. The name `try!` is more invocative of error handling, it's shorter by 2 letters, and it looks fitting in almost all circumstances. One concern about the word `try!` is that it's too invocative of exceptions, but the belief is that this will be overcome with documentation and examples. Close #12037
fix: Remove `rust-analyzer.inlayHints.enable` and set language scope Closes rust-lang#12036 CC rust-lang/rust-analyzer#12027 (comment) The key was left there by mistake in rust-lang#12006. Setting the configuration scope only works if you already have it created, which is fine, but unfortunately not quite discoverable.
add external macro checks to `iter_without_into_iter` and `into_iter_without_iter` Fixes rust-lang#12037 I think it's useful to still lint on local macros, since the user should still be able to add another impl with the `IntoIterator` or `iter` method. I think it's also fairly common to write a macro for generating many impls (e.g. for many similar types), so it'd be nice if we can continue linting in those cases. For that reason I went with `in_external_macro`. I also added a test for `#[allow]`ing the lint while I was at it. changelog: [`iter_without_into_iter`]: don't lint if the `iter` method is defined in an external macro changelog: [`into_iter_without_iter`]: don't lint if the `IntoIterator` impl is defined in an external macro
Removing
io_error
was bad enough, I didn't want to worry too much about naming this macro at the time. The nameif_ok!()
isn't fantastic, and we should probably rename it.try!()
- short, succinct, but can possibly evoke the notion of try/catch exceptions from other languagesok!()
- also short and succinct, but may not always be clear what it's doing.if_ok!()
- works well for let statements, not always clear what it's doing though.Some code that I think should be considered when naming this macro:
Nominating.
The text was updated successfully, but these errors were encountered: