Skip to content

Commit

Permalink
Point to full async fn for future
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Oct 2, 2023
1 parent 8e47113 commit d15124a
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 45 deletions.
5 changes: 3 additions & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1824,7 +1824,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}

let fn_def_id = self.local_def_id(fn_node_id);
self.lower_async_fn_ret_ty(&decl.output, fn_def_id, ret_id, kind)
self.lower_async_fn_ret_ty(&decl.output, fn_def_id, ret_id, kind, fn_span)
} else {
match &decl.output {
FnRetTy::Ty(ty) => {
Expand Down Expand Up @@ -1901,8 +1901,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn_def_id: LocalDefId,
opaque_ty_node_id: NodeId,
fn_kind: FnDeclKind,
fn_span: Span,
) -> hir::FnRetTy<'hir> {
let span = self.lower_span(output.span());
let span = self.lower_span(fn_span);
let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::Async, span, None);

let captured_lifetimes: Vec<_> = self
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/async-await-let-else.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ error[E0277]: `Rc<()>` cannot be sent between threads safely
--> $DIR/async-await-let-else.rs:47:13
|
LL | async fn foo2(x: Option<bool>) {
| - within this `impl Future<Output = ()>`
| ------------------------------ within this `impl Future<Output = ()>`
...
LL | is_send(foo2(Some(true)));
| ------- ^^^^^^^^^^^^^^^^ `Rc<()>` cannot be sent between threads safely
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0053]: method `foo` has an incompatible type for trait
--> $DIR/async-example-desugared-boxed-in-trait.rs:15:28
--> $DIR/async-example-desugared-boxed-in-trait.rs:15:5
|
LL | async fn foo(&self) -> i32 {
| ^^^ expected `Pin<Box<dyn Future<Output = i32>>>`, found future
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Pin<Box<dyn Future<Output = i32>>>`, found future
|
note: type in trait
--> $DIR/async-example-desugared-boxed-in-trait.rs:11:22
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/async-await/in-trait/async-generics-and-bounds.stderr
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
error[E0311]: the parameter type `U` may not live long enough
--> $DIR/async-generics-and-bounds.rs:12:28
--> $DIR/async-generics-and-bounds.rs:12:5
|
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
| ^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the parameter type `U` must be valid for the anonymous lifetime as defined here...
--> $DIR/async-generics-and-bounds.rs:12:18
|
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
| ^
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
--> $DIR/async-generics-and-bounds.rs:12:28
--> $DIR/async-generics-and-bounds.rs:12:5
|
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
| ^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0311]: the parameter type `T` may not live long enough
--> $DIR/async-generics-and-bounds.rs:12:28
--> $DIR/async-generics-and-bounds.rs:12:5
|
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
| ^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the parameter type `T` must be valid for the anonymous lifetime as defined here...
--> $DIR/async-generics-and-bounds.rs:12:18
|
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
| ^
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
--> $DIR/async-generics-and-bounds.rs:12:28
--> $DIR/async-generics-and-bounds.rs:12:5
|
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
| ^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

Expand Down
16 changes: 8 additions & 8 deletions tests/ui/async-await/in-trait/async-generics.stderr
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
error[E0311]: the parameter type `U` may not live long enough
--> $DIR/async-generics.rs:9:28
--> $DIR/async-generics.rs:9:5
|
LL | async fn foo(&self) -> &(T, U);
| ^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the parameter type `U` must be valid for the anonymous lifetime as defined here...
--> $DIR/async-generics.rs:9:18
|
LL | async fn foo(&self) -> &(T, U);
| ^
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
--> $DIR/async-generics.rs:9:28
--> $DIR/async-generics.rs:9:5
|
LL | async fn foo(&self) -> &(T, U);
| ^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0311]: the parameter type `T` may not live long enough
--> $DIR/async-generics.rs:9:28
--> $DIR/async-generics.rs:9:5
|
LL | async fn foo(&self) -> &(T, U);
| ^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the parameter type `T` must be valid for the anonymous lifetime as defined here...
--> $DIR/async-generics.rs:9:18
|
LL | async fn foo(&self) -> &(T, U);
| ^
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
--> $DIR/async-generics.rs:9:28
--> $DIR/async-generics.rs:9:5
|
LL | async fn foo(&self) -> &(T, U);
| ^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/async-await/in-trait/async-recursive-generic.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0733]: recursion in an `async fn` requires boxing
--> $DIR/async-recursive-generic.rs:11:48
--> $DIR/async-recursive-generic.rs:11:5
|
LL | async fn foo_recursive(&self, n: usize) -> T {
| ^ recursive `async fn`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ recursive `async fn`
|
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
= note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/async-await/in-trait/async-recursive.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0733]: recursion in an `async fn` requires boxing
--> $DIR/async-recursive.rs:11:48
--> $DIR/async-recursive.rs:11:5
|
LL | async fn foo_recursive(&self, n: usize) -> i32 {
| ^^^ recursive `async fn`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ recursive `async fn`
|
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
= note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
error[E0053]: method `foo` has an incompatible type for trait
--> $DIR/dont-project-to-specializable-projection.rs:14:35
--> $DIR/dont-project-to-specializable-projection.rs:14:5
|
LL | default async fn foo(_: T) -> &'static str {
| ^^^^^^^^^^^^ expected associated type, found future
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found future
|
note: type in trait
--> $DIR/dont-project-to-specializable-projection.rs:10:27
--> $DIR/dont-project-to-specializable-projection.rs:10:5
|
LL | async fn foo(_: T) -> &'static str;
| ^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: expected signature `fn(_) -> impl Future<Output = &'static str>`
found signature `fn(_) -> impl Future<Output = &'static str>`

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/issue-64130-3-other.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0277]: the trait bound `Foo: Qux` is not satisfied in `impl Future<Output
--> $DIR/issue-64130-3-other.rs:25:12
|
LL | async fn bar() {
| - within this `impl Future<Output = ()>`
| -------------- within this `impl Future<Output = ()>`
...
LL | is_qux(bar());
| ^^^^^ within `impl Future<Output = ()>`, the trait `Qux` is not implemented for `Foo`
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/async-await/issues/issue-67893.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ LL | g(issue_67893::run())
| |
| required by a bound introduced by this call
|
::: $DIR/auxiliary/issue_67893.rs:9:20
::: $DIR/auxiliary/issue_67893.rs:9:1
|
LL | pub async fn run() {
| - within this `impl Future<Output = ()>`
| ------------------ within this `impl Future<Output = ()>`
|
= help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `MutexGuard<'_, ()>`
= note: required because it captures the following types: `Arc<Mutex<()>>`, `MutexGuard<'_, ()>`, `impl Future<Output = ()>`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
error[E0733]: recursion in an `async fn` requires boxing
--> $DIR/mutually-recursive-async-impl-trait-type.rs:5:18
--> $DIR/mutually-recursive-async-impl-trait-type.rs:5:1
|
LL | async fn rec_1() {
| ^ recursive `async fn`
| ^^^^^^^^^^^^^^^^ recursive `async fn`
|
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
= note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion

error[E0733]: recursion in an `async fn` requires boxing
--> $DIR/mutually-recursive-async-impl-trait-type.rs:9:18
--> $DIR/mutually-recursive-async-impl-trait-type.rs:9:1
|
LL | async fn rec_2() {
| ^ recursive `async fn`
| ^^^^^^^^^^^^^^^^ recursive `async fn`
|
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
= note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/partial-drop-partial-reinit.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | gimme_send(foo());
| required by a bound introduced by this call
...
LL | async fn foo() {
| - within this `impl Future<Output = ()>`
| -------------- within this `impl Future<Output = ()>`
|
= help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `NotSend`
= note: required because it appears within the type `(NotSend,)`
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/async-await/recursive-async-impl-trait-type.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0733]: recursion in an `async fn` requires boxing
--> $DIR/recursive-async-impl-trait-type.rs:5:40
--> $DIR/recursive-async-impl-trait-type.rs:5:1
|
LL | async fn recursive_async_function() -> () {
| ^^ recursive `async fn`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ recursive `async fn`
|
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
= note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/suggestions/impl-trait-missing-lifetime.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ error: lifetime may not live long enough
--> $DIR/impl-trait-missing-lifetime.rs:16:69
|
LL | async fn i(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
| -------------- ^^^^^^^^ returning this value requires that `'1` must outlive `'static`
| |
| return type `impl Future<Output = Option<&'static ()>>` contains a lifetime `'1`
| ----------------------------------------------------------------- ^^^^^^^^ returning this value requires that `'1` must outlive `'static`
| |
| return type `impl Future<Output = Option<&'static ()>>` contains a lifetime `'1`

error: aborting due to 3 previous errors

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/suggestions/suggest-ret-on-async-w-late.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/suggest-ret-on-async-w-late.rs:7:5
|
LL | async fn ice(_: &i32) {
| - help: try adding a return type: `-> bool`
| --------------------- help: try adding a return type: `-> bool`
LL | true
| ^^^^ expected `()`, found `bool`

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/typeck/issue-90027-async-fn-return-suggestion.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ error[E0308]: mismatched types
--> $DIR/issue-90027-async-fn-return-suggestion.rs:4:5
|
LL | async fn hello() {
| - help: try adding a return type: `-> i32`
| ---------------- help: try adding a return type: `-> i32`
LL | 0
| ^ expected `()`, found integer

error[E0308]: mismatched types
--> $DIR/issue-90027-async-fn-return-suggestion.rs:9:5
|
LL | async fn world() -> () {
| -- expected `()` because of return type
| ---------------------- expected `()` because of return type
LL | 0
| ^ expected `()`, found integer

Expand Down

0 comments on commit d15124a

Please sign in to comment.