Closed
Description
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
Metadata
Metadata
Assignees
Labels
Area: Async & AwaitArea: Lints (warnings about flaws in source code) such as unused_mut.Async-await issues that are part of the "polish" areaAsync-await issues that have been triaged during a working group meeting.Category: This is a bug.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Status
Done