Skip to content

Commit 65519f5

Browse files
committed
Auto merge of rust-lang#116360 - compiler-errors:async-span, r=oli-obk
Point to full `async fn` for future Semi-follow-up to rust-lang#116296 (comment) cc `@asquared31415`
2 parents 9fbd593 + 2934fe0 commit 65519f5

18 files changed

+68
-64
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1824,7 +1824,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18241824
}
18251825

18261826
let fn_def_id = self.local_def_id(fn_node_id);
1827-
self.lower_async_fn_ret_ty(&decl.output, fn_def_id, ret_id, kind)
1827+
self.lower_async_fn_ret_ty(&decl.output, fn_def_id, ret_id, kind, fn_span)
18281828
} else {
18291829
match &decl.output {
18301830
FnRetTy::Ty(ty) => {
@@ -1901,8 +1901,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19011901
fn_def_id: LocalDefId,
19021902
opaque_ty_node_id: NodeId,
19031903
fn_kind: FnDeclKind,
1904+
fn_span: Span,
19041905
) -> hir::FnRetTy<'hir> {
1905-
let span = self.lower_span(output.span());
1906+
let span = self.lower_span(fn_span);
19061907
let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::Async, span, None);
19071908

19081909
let captured_lifetimes: Vec<_> = self

src/tools/clippy/tests/ui/crashes/ice-10645.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
warning: future cannot be sent between threads safely
2-
--> $DIR/ice-10645.rs:5:35
2+
--> $DIR/ice-10645.rs:5:1
33
|
44
LL | pub async fn bar<'a, T: 'a>(_: T) {}
5-
| ^ future returned by `bar` is not `Send`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `bar` is not `Send`
66
|
77
note: captured value is not `Send`
88
--> $DIR/ice-10645.rs:5:29

src/tools/clippy/tests/ui/future_not_send.stderr

+20-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: future cannot be sent between threads safely
2-
--> $DIR/future_not_send.rs:7:62
2+
--> $DIR/future_not_send.rs:7:1
33
|
44
LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell<usize>) -> bool {
5-
| ^^^^ future returned by `private_future` is not `Send`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `private_future` is not `Send`
66
|
77
note: future is not `Send` as this value is used across an await
88
--> $DIR/future_not_send.rs:9:20
@@ -23,10 +23,10 @@ LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell<usize>) -> bool {
2323
= help: to override `-D warnings` add `#[allow(clippy::future_not_send)]`
2424

2525
error: future cannot be sent between threads safely
26-
--> $DIR/future_not_send.rs:12:42
26+
--> $DIR/future_not_send.rs:12:1
2727
|
2828
LL | pub async fn public_future(rc: Rc<[u8]>) {
29-
| ^ future returned by `public_future` is not `Send`
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `public_future` is not `Send`
3030
|
3131
note: future is not `Send` as this value is used across an await
3232
--> $DIR/future_not_send.rs:14:20
@@ -39,10 +39,10 @@ LL | async { true }.await;
3939
= note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send`
4040

4141
error: future cannot be sent between threads safely
42-
--> $DIR/future_not_send.rs:21:63
42+
--> $DIR/future_not_send.rs:21:1
4343
|
4444
LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell<usize>) -> bool {
45-
| ^^^^ future returned by `private_future2` is not `Send`
45+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `private_future2` is not `Send`
4646
|
4747
note: captured value is not `Send`
4848
--> $DIR/future_not_send.rs:21:26
@@ -58,10 +58,10 @@ LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell<usize>) -> bool {
5858
= note: `std::cell::Cell<usize>` doesn't implement `std::marker::Sync`
5959

6060
error: future cannot be sent between threads safely
61-
--> $DIR/future_not_send.rs:26:43
61+
--> $DIR/future_not_send.rs:26:1
6262
|
6363
LL | pub async fn public_future2(rc: Rc<[u8]>) {}
64-
| ^ future returned by `public_future2` is not `Send`
64+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `public_future2` is not `Send`
6565
|
6666
note: captured value is not `Send`
6767
--> $DIR/future_not_send.rs:26:29
@@ -71,10 +71,10 @@ LL | pub async fn public_future2(rc: Rc<[u8]>) {}
7171
= note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send`
7272

7373
error: future cannot be sent between threads safely
74-
--> $DIR/future_not_send.rs:38:39
74+
--> $DIR/future_not_send.rs:38:5
7575
|
7676
LL | async fn private_future(&self) -> usize {
77-
| ^^^^^ future returned by `private_future` is not `Send`
77+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `private_future` is not `Send`
7878
|
7979
note: future is not `Send` as this value is used across an await
8080
--> $DIR/future_not_send.rs:40:24
@@ -87,10 +87,10 @@ LL | async { true }.await;
8787
= note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync`
8888

8989
error: future cannot be sent between threads safely
90-
--> $DIR/future_not_send.rs:44:39
90+
--> $DIR/future_not_send.rs:44:5
9191
|
9292
LL | pub async fn public_future(&self) {
93-
| ^ future returned by `public_future` is not `Send`
93+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `public_future` is not `Send`
9494
|
9595
note: captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync`
9696
--> $DIR/future_not_send.rs:44:32
@@ -100,10 +100,13 @@ LL | pub async fn public_future(&self) {
100100
= note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync`
101101

102102
error: future cannot be sent between threads safely
103-
--> $DIR/future_not_send.rs:55:37
103+
--> $DIR/future_not_send.rs:55:1
104104
|
105-
LL | async fn generic_future<T>(t: T) -> T
106-
| ^ future returned by `generic_future` is not `Send`
105+
LL | / async fn generic_future<T>(t: T) -> T
106+
LL | |
107+
LL | | where
108+
LL | | T: Send,
109+
| |____________^ future returned by `generic_future` is not `Send`
107110
|
108111
note: future is not `Send` as this value is used across an await
109112
--> $DIR/future_not_send.rs:61:20
@@ -115,10 +118,10 @@ LL | async { true }.await;
115118
= note: `T` doesn't implement `std::marker::Sync`
116119

117120
error: future cannot be sent between threads safely
118-
--> $DIR/future_not_send.rs:73:34
121+
--> $DIR/future_not_send.rs:73:1
119122
|
120123
LL | async fn unclear_future<T>(t: T) {}
121-
| ^ future returned by `unclear_future` is not `Send`
124+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `unclear_future` is not `Send`
122125
|
123126
note: captured value is not `Send`
124127
--> $DIR/future_not_send.rs:73:28

tests/ui/async-await/async-await-let-else.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ error[E0277]: `Rc<()>` cannot be sent between threads safely
2222
--> $DIR/async-await-let-else.rs:47:13
2323
|
2424
LL | async fn foo2(x: Option<bool>) {
25-
| - within this `impl Future<Output = ()>`
25+
| ------------------------------ within this `impl Future<Output = ()>`
2626
...
2727
LL | is_send(foo2(Some(true)));
2828
| ------- ^^^^^^^^^^^^^^^^ `Rc<()>` cannot be sent between threads safely

tests/ui/async-await/in-trait/async-example-desugared-boxed-in-trait.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0053]: method `foo` has an incompatible type for trait
2-
--> $DIR/async-example-desugared-boxed-in-trait.rs:15:28
2+
--> $DIR/async-example-desugared-boxed-in-trait.rs:15:5
33
|
44
LL | async fn foo(&self) -> i32 {
5-
| ^^^ expected `Pin<Box<dyn Future<Output = i32>>>`, found future
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Pin<Box<dyn Future<Output = i32>>>`, found future
66
|
77
note: type in trait
88
--> $DIR/async-example-desugared-boxed-in-trait.rs:11:22

tests/ui/async-await/in-trait/async-generics-and-bounds.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
error[E0311]: the parameter type `U` may not live long enough
2-
--> $DIR/async-generics-and-bounds.rs:12:28
2+
--> $DIR/async-generics-and-bounds.rs:12:5
33
|
44
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
5-
| ^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
note: the parameter type `U` must be valid for the anonymous lifetime as defined here...
88
--> $DIR/async-generics-and-bounds.rs:12:18
99
|
1010
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
1111
| ^
1212
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
13-
--> $DIR/async-generics-and-bounds.rs:12:28
13+
--> $DIR/async-generics-and-bounds.rs:12:5
1414
|
1515
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
16-
| ^^^^^^^
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1717

1818
error[E0311]: the parameter type `T` may not live long enough
19-
--> $DIR/async-generics-and-bounds.rs:12:28
19+
--> $DIR/async-generics-and-bounds.rs:12:5
2020
|
2121
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
22-
| ^^^^^^^
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2323
|
2424
note: the parameter type `T` must be valid for the anonymous lifetime as defined here...
2525
--> $DIR/async-generics-and-bounds.rs:12:18
2626
|
2727
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
2828
| ^
2929
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
30-
--> $DIR/async-generics-and-bounds.rs:12:28
30+
--> $DIR/async-generics-and-bounds.rs:12:5
3131
|
3232
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
33-
| ^^^^^^^
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3434

3535
error: aborting due to 2 previous errors
3636

tests/ui/async-await/in-trait/async-generics.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
error[E0311]: the parameter type `U` may not live long enough
2-
--> $DIR/async-generics.rs:9:28
2+
--> $DIR/async-generics.rs:9:5
33
|
44
LL | async fn foo(&self) -> &(T, U);
5-
| ^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
note: the parameter type `U` must be valid for the anonymous lifetime as defined here...
88
--> $DIR/async-generics.rs:9:18
99
|
1010
LL | async fn foo(&self) -> &(T, U);
1111
| ^
1212
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
13-
--> $DIR/async-generics.rs:9:28
13+
--> $DIR/async-generics.rs:9:5
1414
|
1515
LL | async fn foo(&self) -> &(T, U);
16-
| ^^^^^^^
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1717

1818
error[E0311]: the parameter type `T` may not live long enough
19-
--> $DIR/async-generics.rs:9:28
19+
--> $DIR/async-generics.rs:9:5
2020
|
2121
LL | async fn foo(&self) -> &(T, U);
22-
| ^^^^^^^
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2323
|
2424
note: the parameter type `T` must be valid for the anonymous lifetime as defined here...
2525
--> $DIR/async-generics.rs:9:18
2626
|
2727
LL | async fn foo(&self) -> &(T, U);
2828
| ^
2929
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
30-
--> $DIR/async-generics.rs:9:28
30+
--> $DIR/async-generics.rs:9:5
3131
|
3232
LL | async fn foo(&self) -> &(T, U);
33-
| ^^^^^^^
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3434

3535
error: aborting due to 2 previous errors
3636

tests/ui/async-await/in-trait/async-recursive-generic.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0733]: recursion in an `async fn` requires boxing
2-
--> $DIR/async-recursive-generic.rs:11:48
2+
--> $DIR/async-recursive-generic.rs:11:5
33
|
44
LL | async fn foo_recursive(&self, n: usize) -> T {
5-
| ^ recursive `async fn`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ recursive `async fn`
66
|
77
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
88
= note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion

tests/ui/async-await/in-trait/async-recursive.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0733]: recursion in an `async fn` requires boxing
2-
--> $DIR/async-recursive.rs:11:48
2+
--> $DIR/async-recursive.rs:11:5
33
|
44
LL | async fn foo_recursive(&self, n: usize) -> i32 {
5-
| ^^^ recursive `async fn`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ recursive `async fn`
66
|
77
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
88
= note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion

tests/ui/async-await/in-trait/dont-project-to-specializable-projection.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
error[E0053]: method `foo` has an incompatible type for trait
2-
--> $DIR/dont-project-to-specializable-projection.rs:14:35
2+
--> $DIR/dont-project-to-specializable-projection.rs:14:5
33
|
44
LL | default async fn foo(_: T) -> &'static str {
5-
| ^^^^^^^^^^^^ expected associated type, found future
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found future
66
|
77
note: type in trait
8-
--> $DIR/dont-project-to-specializable-projection.rs:10:27
8+
--> $DIR/dont-project-to-specializable-projection.rs:10:5
99
|
1010
LL | async fn foo(_: T) -> &'static str;
11-
| ^^^^^^^^^^^^
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
= note: expected signature `fn(_) -> impl Future<Output = &'static str>`
1313
found signature `fn(_) -> impl Future<Output = &'static str>`
1414

tests/ui/async-await/issue-64130-3-other.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: the trait bound `Foo: Qux` is not satisfied in `impl Future<Output
22
--> $DIR/issue-64130-3-other.rs:25:12
33
|
44
LL | async fn bar() {
5-
| - within this `impl Future<Output = ()>`
5+
| -------------- within this `impl Future<Output = ()>`
66
...
77
LL | is_qux(bar());
88
| ^^^^^ within `impl Future<Output = ()>`, the trait `Qux` is not implemented for `Foo`

tests/ui/async-await/issues/issue-67893.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ LL | g(issue_67893::run())
66
| |
77
| required by a bound introduced by this call
88
|
9-
::: $DIR/auxiliary/issue_67893.rs:9:20
9+
::: $DIR/auxiliary/issue_67893.rs:9:1
1010
|
1111
LL | pub async fn run() {
12-
| - within this `impl Future<Output = ()>`
12+
| ------------------ within this `impl Future<Output = ()>`
1313
|
1414
= help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `MutexGuard<'_, ()>`
1515
= note: required because it captures the following types: `Arc<Mutex<()>>`, `MutexGuard<'_, ()>`, `impl Future<Output = ()>`

tests/ui/async-await/mutually-recursive-async-impl-trait-type.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error[E0733]: recursion in an `async fn` requires boxing
2-
--> $DIR/mutually-recursive-async-impl-trait-type.rs:5:18
2+
--> $DIR/mutually-recursive-async-impl-trait-type.rs:5:1
33
|
44
LL | async fn rec_1() {
5-
| ^ recursive `async fn`
5+
| ^^^^^^^^^^^^^^^^ recursive `async fn`
66
|
77
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
88
= note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion
99

1010
error[E0733]: recursion in an `async fn` requires boxing
11-
--> $DIR/mutually-recursive-async-impl-trait-type.rs:9:18
11+
--> $DIR/mutually-recursive-async-impl-trait-type.rs:9:1
1212
|
1313
LL | async fn rec_2() {
14-
| ^ recursive `async fn`
14+
| ^^^^^^^^^^^^^^^^ recursive `async fn`
1515
|
1616
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
1717
= note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion

tests/ui/async-await/partial-drop-partial-reinit.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | gimme_send(foo());
77
| required by a bound introduced by this call
88
...
99
LL | async fn foo() {
10-
| - within this `impl Future<Output = ()>`
10+
| -------------- within this `impl Future<Output = ()>`
1111
|
1212
= help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `NotSend`
1313
= note: required because it appears within the type `(NotSend,)`

tests/ui/async-await/recursive-async-impl-trait-type.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0733]: recursion in an `async fn` requires boxing
2-
--> $DIR/recursive-async-impl-trait-type.rs:5:40
2+
--> $DIR/recursive-async-impl-trait-type.rs:5:1
33
|
44
LL | async fn recursive_async_function() -> () {
5-
| ^^ recursive `async fn`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ recursive `async fn`
66
|
77
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
88
= note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion

tests/ui/suggestions/impl-trait-missing-lifetime.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ error: lifetime may not live long enough
2626
--> $DIR/impl-trait-missing-lifetime.rs:16:69
2727
|
2828
LL | async fn i(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
29-
| -------------- ^^^^^^^^ returning this value requires that `'1` must outlive `'static`
30-
| |
31-
| return type `impl Future<Output = Option<&'static ()>>` contains a lifetime `'1`
29+
| ----------------------------------------------------------------- ^^^^^^^^ returning this value requires that `'1` must outlive `'static`
30+
| |
31+
| return type `impl Future<Output = Option<&'static ()>>` contains a lifetime `'1`
3232

3333
error: aborting due to 3 previous errors
3434

tests/ui/suggestions/suggest-ret-on-async-w-late.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/suggest-ret-on-async-w-late.rs:7:5
33
|
44
LL | async fn ice(_: &i32) {
5-
| - help: try adding a return type: `-> bool`
5+
| --------------------- help: try adding a return type: `-> bool`
66
LL | true
77
| ^^^^ expected `()`, found `bool`
88

tests/ui/typeck/issue-90027-async-fn-return-suggestion.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ error[E0308]: mismatched types
22
--> $DIR/issue-90027-async-fn-return-suggestion.rs:4:5
33
|
44
LL | async fn hello() {
5-
| - help: try adding a return type: `-> i32`
5+
| ---------------- help: try adding a return type: `-> i32`
66
LL | 0
77
| ^ expected `()`, found integer
88

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

0 commit comments

Comments
 (0)