Skip to content

Commit 3025465

Browse files
committed
Use return type Span on async fns instead of whole fn def Span
1 parent e5efc33 commit 3025465

19 files changed

+63
-77
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,7 +1669,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16691669
let output = match coro {
16701670
Some(coro) => {
16711671
let fn_def_id = self.local_def_id(fn_node_id);
1672-
self.lower_coroutine_fn_ret_ty(&decl.output, fn_def_id, coro, kind, fn_span)
1672+
self.lower_coroutine_fn_ret_ty(&decl.output, fn_def_id, coro, kind)
16731673
}
16741674
None => match &decl.output {
16751675
FnRetTy::Ty(ty) => {
@@ -1754,9 +1754,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17541754
fn_def_id: LocalDefId,
17551755
coro: CoroutineKind,
17561756
fn_kind: FnDeclKind,
1757-
fn_span: Span,
17581757
) -> hir::FnRetTy<'hir> {
1759-
let span = self.lower_span(fn_span);
1758+
let span = self.lower_span(output.span());
17601759

17611760
let (opaque_ty_node_id, allowed_features) = match coro {
17621761
CoroutineKind::Async { return_impl_trait_id, .. } => (return_impl_trait_id, None),

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

Lines changed: 1 addition & 1 deletion
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/async-fn/recurse-ice-129215.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ LL | a()
77
= help: the trait `Future` is not implemented for `()`
88

99
error[E0277]: `()` is not a future
10-
--> $DIR/recurse-ice-129215.rs:3:1
10+
--> $DIR/recurse-ice-129215.rs:3:13
1111
|
1212
LL | async fn a() {
13-
| ^^^^^^^^^^^^ `()` is not a future
13+
| ^ `()` is not a future
1414
|
1515
= help: the trait `Future` is not implemented for `()`
1616

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

Lines changed: 2 additions & 2 deletions
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:11:5
2+
--> $DIR/async-example-desugared-boxed-in-trait.rs:11:28
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:7:22

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ warning: impl trait in impl method signature does not match trait method signatu
22
--> $DIR/async-example-desugared-boxed.rs:14:22
33
|
44
LL | async fn foo(&self) -> i32;
5-
| --------------------------- return type from trait method defined here
5+
| --- return type from trait method defined here
66
...
77
LL | fn foo(&self) -> Pin<Box<dyn Future<Output = i32> + '_>> {
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ warning: impl trait in impl method signature does not match trait method signatu
22
--> $DIR/async-example-desugared-manual.rs:22:22
33
|
44
LL | async fn foo(&self) -> i32;
5-
| --------------------------- return type from trait method defined here
5+
| --- return type from trait method defined here
66
...
77
LL | fn foo(&self) -> MyFuture {
88
| ^^^^^^^^

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
error[E0311]: the parameter type `T` may not live long enough
2-
--> $DIR/async-generics-and-bounds.rs:8:5
2+
--> $DIR/async-generics-and-bounds.rs:8:28
33
|
44
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
5-
| ^^^^^^^^^^^^^-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
| | |
7-
| | the parameter type `T` must be valid for the anonymous lifetime as defined here...
8-
| ...so that the reference type `&(T, U)` does not outlive the data it points at
5+
| - ^^^^^^^ ...so that the reference type `&(T, U)` does not outlive the data it points at
6+
| |
7+
| the parameter type `T` must be valid for the anonymous lifetime as defined here...
98
|
109
help: consider adding an explicit lifetime bound
1110
|
1211
LL | async fn foo<'a>(&'a self) -> &'a (T, U) where T: Debug + Sized, U: Hash, T: 'a;
1312
| ++++ ++ ++ +++++++
1413

1514
error[E0311]: the parameter type `U` may not live long enough
16-
--> $DIR/async-generics-and-bounds.rs:8:5
15+
--> $DIR/async-generics-and-bounds.rs:8:28
1716
|
1817
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
19-
| ^^^^^^^^^^^^^-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20-
| | |
21-
| | the parameter type `U` must be valid for the anonymous lifetime as defined here...
22-
| ...so that the reference type `&(T, U)` does not outlive the data it points at
18+
| - ^^^^^^^ ...so that the reference type `&(T, U)` does not outlive the data it points at
19+
| |
20+
| the parameter type `U` must be valid for the anonymous lifetime as defined here...
2321
|
2422
help: consider adding an explicit lifetime bound
2523
|

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
error[E0311]: the parameter type `T` may not live long enough
2-
--> $DIR/async-generics.rs:5:5
2+
--> $DIR/async-generics.rs:5:28
33
|
44
LL | async fn foo(&self) -> &(T, U);
5-
| ^^^^^^^^^^^^^-^^^^^^^^^^^^^^^^^
6-
| | |
7-
| | the parameter type `T` must be valid for the anonymous lifetime as defined here...
8-
| ...so that the reference type `&(T, U)` does not outlive the data it points at
5+
| - ^^^^^^^ ...so that the reference type `&(T, U)` does not outlive the data it points at
6+
| |
7+
| the parameter type `T` must be valid for the anonymous lifetime as defined here...
98
|
109
help: consider adding an explicit lifetime bound
1110
|
1211
LL | async fn foo<'a>(&'a self) -> &'a (T, U) where T: 'a;
1312
| ++++ ++ ++ +++++++++++
1413

1514
error[E0311]: the parameter type `U` may not live long enough
16-
--> $DIR/async-generics.rs:5:5
15+
--> $DIR/async-generics.rs:5:28
1716
|
1817
LL | async fn foo(&self) -> &(T, U);
19-
| ^^^^^^^^^^^^^-^^^^^^^^^^^^^^^^^
20-
| | |
21-
| | the parameter type `U` must be valid for the anonymous lifetime as defined here...
22-
| ...so that the reference type `&(T, U)` does not outlive the data it points at
18+
| - ^^^^^^^ ...so that the reference type `&(T, U)` does not outlive the data it points at
19+
| |
20+
| the parameter type `U` must be valid for the anonymous lifetime as defined here...
2321
|
2422
help: consider adding an explicit lifetime bound
2523
|

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

Lines changed: 4 additions & 4 deletions
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:5
2+
--> $DIR/dont-project-to-specializable-projection.rs:14:35
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:5
8+
--> $DIR/dont-project-to-specializable-projection.rs:10:27
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/inference_var_self_argument.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ LL | async fn foo(self: &dyn Foo) {
88
= help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`)
99

1010
error[E0038]: the trait `Foo` is not dyn compatible
11-
--> $DIR/inference_var_self_argument.rs:5:5
11+
--> $DIR/inference_var_self_argument.rs:5:33
1212
|
1313
LL | async fn foo(self: &dyn Foo) {
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Foo` is not dyn compatible
14+
| ^ `Foo` is not dyn compatible
1515
|
1616
note: for a trait to be dyn compatible it needs to allow building a vtable
1717
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>

0 commit comments

Comments
 (0)