Skip to content
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

Missing must_use on type implementing Future #13886

Open
CryZe opened this issue Dec 27, 2024 · 0 comments · May be fixed by #14066
Open

Missing must_use on type implementing Future #13886

CryZe opened this issue Dec 27, 2024 · 0 comments · May be fixed by #14066
Labels
A-lint Area: New lints

Comments

@CryZe
Copy link

CryZe commented Dec 27, 2024

What it does

If you write an async fn:

async fn foo() { }

then the anonymous type implementing the Future trait automatically has a must_use annotation.
If you instead provide your own type implementing the Future trait:

struct FooFuture { ... }

impl Future for FooFuture { ... }

fn foo() -> FooFuture { ... }

then it's very easy to forget to annotate the type as must_use.

We just ran into this exact scenario where we were debugging for like an hour or so until we found the missing .await with no warning to be found by the compiler at all as it was a custom Future implementing struct.

Advantage

  • The compiler will warn if you forget to .await a future.
  • You don't need to debug for 1 hour.

Drawbacks

None

Example

struct FooFuture { ... }

impl Future for FooFuture { ... }

Could be written as:

#[must_use]
struct FooFuture { ... }

impl Future for FooFuture { ... }

(Possibly with the same explanation that async fn gives)

@CryZe CryZe added the A-lint Area: New lints label Dec 27, 2024
@rmehri01 rmehri01 linked a pull request Jan 23, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant