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

New #[must_use] behaviour for async methods does not apply to Pin<Box<dyn Future<Output = ()>>> #111458

Closed
tropicbliss opened this issue May 11, 2023 · 7 comments · Fixed by #118054
Assignees
Labels
A-async-await Area: Async & Await A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. AsyncAwait-Polish Async-await issues that are part of the "polish" area AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tropicbliss
Copy link

tropicbliss commented May 11, 2023

Defining traits that contain methods that return such a type:

pub trait Hello {
    fn hi(&self) -> Pin<Box<dyn Future<Output = i32>>> {
        Box::pin(async { 42 })
    }
}

struct Number(i32);

impl Hello for Number {}

async fn say_hello() {
  let number = Number(42);
  number.hi().await;
}

The compiler should probably have warned me about not using the Output of the Future, consistent with the behaviour of async functions in Rust 1.67.0. This will also work without the need for traits but async traits is one of the most common use cases for such a type.

Meta

rustc --version --verbose:

rustc 1.69.0 (84c898d65 2023-04-16)
binary: rustc
commit-hash: 84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc
commit-date: 2023-04-16
host: x86_64-unknown-linux-gnu
release: 1.69.0
LLVM version: 15.0.7

Also tested on:
rustc 1.71.0-nightly (f9a6b7158 2023-05-05)
binary: rustc
commit-hash: f9a6b71580cd53dd4491d9bb6400f7ee841d9c22
commit-date: 2023-05-05
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.2
Backtrace

@tropicbliss tropicbliss added the C-bug Category: This is a bug. label May 11, 2023
@tropicbliss tropicbliss changed the title New #[must_use] behaviour for async methods does not apply to Pin<Box<dyn Future<Output = ()>>> New #[must_use] behaviour for async methods does not apply to Pin<Box<dyn Future<Output = ()>>> in traits May 11, 2023
@tropicbliss tropicbliss changed the title New #[must_use] behaviour for async methods does not apply to Pin<Box<dyn Future<Output = ()>>> in traits New #[must_use] behaviour for async methods does not apply to Pin<Box<dyn Future<Output = ()>>> May 11, 2023
@ChrisDenton ChrisDenton added the needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. label Jul 16, 2023
@fmease fmease added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-async-await Area: Async & Await and removed needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. labels Sep 7, 2023
@eholk
Copy link
Contributor

eholk commented Oct 9, 2023

We looked at this as the wg-async triage meeting today. We agree this is a bug and that the behavior should be consistent with #[must_use] on async fn and/or -> impl Future.

This is also likely a good first issue for someone wanting to contribute to async.

@eholk eholk added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. AsyncAwait-Polish Async-await issues that are part of the "polish" area AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. labels Oct 9, 2023
@thosakwe
Copy link

We looked at this as the wg-async triage meeting today. We agree this is a bug and that the behavior should be consistent with #[must_use] on async fn and/or -> impl Future.

This is also likely a good first issue for someone wanting to contribute to async.

Would you say this is also a good issue for a first-time contributor to Rust?

I'm not super familiar with the language, but I want to contribute to open source compilers, so I'm hoping to potentially take on this task.

@tsafacjo
Copy link

tsafacjo commented Nov 1, 2023

Can I take this ?

@eholk
Copy link
Contributor

eholk commented Nov 3, 2023

Either one of you (@thosakwe or @tsafacjo) are welcome to work on this! If it's your first time contributing to Rust, it might take a while to ramp up on it, but I find the best way to do that is to just do it. If you decided to have a go at it, feel free to ask any questions you have either here or in #wg-async. I tend to watch #wg-async closer than GitHub issues, so you'll probably get a more prompt reply there.

@Dylan-DPC
Copy link
Member

@tsafacjo this issue wasn't claimed so you are free to claim and work on it if you still are interested. Kindly comment with @rustbot claim to claim the issue.

@max-niederman
Copy link
Contributor

@rustbot claim

@max-niederman
Copy link
Contributor

This is also a very special case of #102238

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. AsyncAwait-Polish Async-await issues that are part of the "polish" area AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
Status: Done
8 participants