-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add messages to Option
's and Result
's must_use
annotation for is_*
#62431
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add messages to Option
's and Result
's must_use
annotation for is_*
#62431
Conversation
@@ -201,7 +201,8 @@ impl<T> Option<T> { | |||
/// ``` | |||
/// | |||
/// [`None`]: #variant.None | |||
#[must_use] | |||
#[must_use = "if you intended to assert that this doesn't have a value, consider \ | |||
`.and_then(|| panic!(\"`Option` had a value when expected `None`\"))` instead"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this message is too long. How about the suggestion is .ok_or(()).unwrap_err()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong opinion; I just wanted to give a message as nice as the .unwrap()
ones do.
Maybe there's a way to combine them? .ok_or("Option::None").unwrap_err()
or similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just tell the user to wrap it in an assert!()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really we should add an expect_none
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #62596.
📌 Commit 9b0623d has been approved by |
…s_-methods, r=scottmcm Add messages to `Option`'s and `Result`'s `must_use` annotation for `is_*` r? @RalfJung
Rollup of 12 pull requests Successful merges: - #61535 (Coherence test when a generic type param has a default value from an associated type) - #62274 (rustc_mir: follow FalseUnwind's real_target edge in qualify_consts.) - #62431 (Add messages to `Option`'s and `Result`'s `must_use` annotation for `is_*`) - #62453 (in which we suggest anonymizing single-use lifetimes in paths ) - #62568 (Replace unsafe_destructor_blind_to_params with may_dangle) - #62578 (Add test for #49919) - #62595 (Document that the crate keyword refers to the project root) - #62599 (move mem::uninitialized deprecation back by 1 release, to 1.39) - #62605 (Emit dropped unemitted errors to aid in ICE debugging) - #62607 (Correctly break out of recovery loop) - #62608 (`async unsafe fn` tests) - #62623 (downgrade indirect_structural_match lint to allow) Failed merges: r? @ghost
r? @RalfJung