-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Make Option<T> #[must_use]
if T is
#71368
Comments
Why do you create an option and do nothing with it? |
did I minimize this example too far?... actual code was closer to:
|
The issue is that |
Also see #67387 ( |
Nominating for @rust-lang/lang consideration. This is another case where extending I was pondering why it makes sense, and I think the reason is pretty clear -- an |
From wg-async-foundations triage: marking On Deck, because forgetting to await is a fairly common thing, and part of the learnability story for async/await is making sure you don't do that. |
How feasible would it be to detect taking a |
What about making the enum variant constructors themselves |
Marking the variant constructor Also, I think we might well want to warn on code like the following: fn foo() -> Option<impl Future> { ... }
fn bar() {
foo();
} I'm not quite I understand what @joshtriplett is proposing. It sounds like saying "if you construct a enum or struct variant that contains a I'd like to ask: what is the resistance to making |
I support making In https://fuchsia-review.googlesource.com/c/fuchsia/+/501960/9/src/sys/component_manager/src/capability.rs#173, I wanted to have a trait method returning a
I wanted |
#[must_use]
if T is
I think Option should be Actually checked the |
Not sure if this should be in another issue, but I'd like this to be supported for types other than Options. I'm writing an actor library, where sending a message to an actor returns an I'd love to be able to mark it as impl<T: MustUse> MustUse for ActorResp<T> {
const REASON: &'static str = "This ActorResp resolves to type that must be used";
} With some more nightly features, this could lead to very nice messages: impl<T: MustUse> MustUse for ActorResp<T> {
const REASON: &'static str = const_format!("This ActorResp resolves to `{}`, which must be used: {}", type_name::<T>(), T::REASON);
} |
This allows us to mark ActionOption as `#[must_use]`, which helps prevent ignoring actions accidentally (e.g. by forgetting to handle a return value). See rust-lang/rust#71368 for more context.
I was recently refactoring some code that originally looked like this (minimized):
bar() was far away from the definition of foo().
I had need to refactor the code so that foo was also async, and so now I had:
This gives no compiler diagnostic and instead the body of foo is not executed.
The text was updated successfully, but these errors were encountered: