-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 core::hint::must_use #94723
Add core::hint::must_use #94723
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
This seems pretty elegant, but I suppose there are a couple language-altering alternatives that spring to mind:
#[must_use]
{
some_expr
} I feel like the second option in particular feels somewhat nice, though it's definitely more work to implement and may have design problems I'm missing. It feels a little more "native" in some sense, and might make a slight difference in some subtle edge cases -- I'm not sure whether for example type inference will always 'see through' the identity function, whereas through just a block it might be easier to do so. But I don't have immediate cases that I can think of. |
That said, I would be totally fine adding this as unstable (r=me), if you want to file a tracking issue for it (maybe with my options as "questions", or feel free to r? a libs-api member if you want another pair of eyes from the team proper. |
📌 Commit b2473e9 has been approved by |
Rollup of 5 pull requests Successful merges: - rust-lang#94689 (Use impl substs in `#[rustc_on_unimplemented]`) - rust-lang#94714 (Enable `close_read_wakes_up` test on Windows) - rust-lang#94723 (Add core::hint::must_use) - rust-lang#94724 (unix: Avoid name conversions in `remove_dir_all_recursive`) - rust-lang#94730 (Reverted atomic_mut_ptr feature removal causing compilation break) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
The example code in this documentation is minimized from a real-world situation in the
anyhow
crate where this function would have been valuable.Having this provided by the standard library is especially useful for proc macros, even more than for macro_rules. That's because proc macro crates aren't allowed to export anything other than macros, so they couldn't make their own
must_use
function for their macro-generated code to call.Rendered documentation