-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 it more clear what an about async fn's returns when referring to what it returns #76765
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,9 @@ error[E0623]: lifetime mismatch | |
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> { | ||
| ------ ^^^^^^^^^^^^^^ | ||
| | | | ||
| | ...but data from `b` is returned here | ||
| this parameter and the return type are declared with different lifetimes... | ||
| | ...but data from `b` is held across an await point here | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, this wording doesn't really work if the error is in the function signature itself. I'm confused why the span is pointing here, but one way to make the diagnostic less wrong is to remove the word "here". Then we're just telling you what's happening and providing a span that might help. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good, when I find time (hopefully tomorrow) I will dig into these comments! |
||
| | this `async fn` implicitly returns an `impl Future<Output = impl Trait<'a>>` | ||
| this parameter and the returned future are declared with different lifetimes... | ||
|
||
error: aborting due to previous error | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/issue-76547.rs:19:14 | ||
| | ||
LL | async fn fut(bufs: &mut [&mut [u8]]) { | ||
| ^^^^ - - let's call the lifetime of this reference `'2` | ||
| | | | ||
| | let's call the lifetime of this reference `'1` | ||
| assignment requires that `'1` must outlive `'2` | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/issue-76547.rs:33:15 | ||
| | ||
LL | async fn fut2(bufs: &mut [&mut [u8]]) -> i32 { | ||
| ^^^^ - - let's call the lifetime of this reference `'2` | ||
| | | | ||
| | let's call the lifetime of this reference `'1` | ||
| assignment requires that `'1` must outlive `'2` | ||
|
||
error: aborting due to 2 previous errors | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Test for diagnostic improvement issue #76547 | ||
// edition:2018 | ||
|
||
use std::{ | ||
future::Future, | ||
task::{Context, Poll} | ||
}; | ||
use std::pin::Pin; | ||
|
||
pub struct ListFut<'a>(&'a mut [&'a mut [u8]]); | ||
impl<'a> Future for ListFut<'a> { | ||
type Output = (); | ||
|
||
fn poll(self: Pin<&mut Self>, _cx: &mut Context) -> Poll<Self::Output> { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
async fn fut(bufs: &mut [&mut [u8]]) { | ||
ListFut(bufs).await | ||
//~^ ERROR lifetime mismatch | ||
} | ||
|
||
pub struct ListFut2<'a>(&'a mut [&'a mut [u8]]); | ||
impl<'a> Future for ListFut2<'a> { | ||
type Output = i32; | ||
|
||
fn poll(self: Pin<&mut Self>, _cx: &mut Context) -> Poll<Self::Output> { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
async fn fut2(bufs: &mut [&mut [u8]]) -> i32 { | ||
ListFut2(bufs).await | ||
//~^ ERROR lifetime mismatch | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
error[E0623]: lifetime mismatch | ||
--> $DIR/issue-76547.rs:20:13 | ||
| | ||
LL | async fn fut(bufs: &mut [&mut [u8]]) { | ||
| --------- - | ||
| | | | ||
| | this `async fn` implicitly returns an `impl Future<Output = ()>` | ||
| this parameter and the returned future are declared with different lifetimes... | ||
LL | ListFut(bufs).await | ||
| ^^^^ ...but data from `bufs` is held across an await point here | ||
|
||
error[E0623]: lifetime mismatch | ||
--> $DIR/issue-76547.rs:34:14 | ||
| | ||
LL | async fn fut2(bufs: &mut [&mut [u8]]) -> i32 { | ||
| --------- --- | ||
| | | | ||
| | this `async fn` implicitly returns an `impl Future<Output = i32>` | ||
| this parameter and the returned future are declared with different lifetimes... | ||
LL | ListFut2(bufs).await | ||
| ^^^^ ...but data from `bufs` is held across an await point here | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0623`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc #78755