-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #76765 - guswynn:async_return, r=tmandry
Make it more clear what an about async fn's returns when referring to what it returns see #76547 This is *likely* not the ONLY place that this happens to be unclear, but we can move this fn to rustc_middle or something like that and reuse it if need be, to apply it to more diagnostics One outstanding question I have is, if the fn returns (), should I make the message more clear (what about `fn f()` vs `fn f() -> ()`, can you tell those apart in the hir?) R? `@tmandry` `@rustbot` modify labels +A-diagnostics +T-compiler
- Loading branch information
Showing
13 changed files
with
351 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.