Skip to content

Commit 7b2eaa3

Browse files
Restore impl Future<Output = Type> to async blocks
1 parent a40c595 commit 7b2eaa3

13 files changed

+36
-23
lines changed

compiler/rustc_middle/src/ty/print/pretty.rs

+20-7
Original file line numberDiff line numberDiff line change
@@ -912,12 +912,25 @@ pub trait PrettyPrinter<'tcx>:
912912
}
913913

914914
for (assoc_item_def_id, term) in assoc_items {
915-
// Skip printing `<[generator@] as Generator<_>>::Return` from async blocks
916-
if let Some(ty) = term.skip_binder().ty() &&
917-
let ty::Projection(ty::ProjectionTy { item_def_id, .. }) = ty.kind() &&
918-
Some(*item_def_id) == self.tcx().lang_items().generator_return() {
919-
continue;
920-
}
915+
// Skip printing `<[generator@] as Generator<_>>::Return` from async blocks,
916+
// unless we can find out what generator return type it comes from.
917+
let term = if let Some(ty) = term.skip_binder().ty()
918+
&& let ty::Projection(ty::ProjectionTy { item_def_id, substs }) = ty.kind()
919+
&& Some(*item_def_id) == self.tcx().lang_items().generator_return()
920+
{
921+
if let ty::Generator(_, substs, _) = substs.type_at(0).kind() {
922+
let return_ty = substs.as_generator().return_ty();
923+
if !return_ty.is_ty_infer() {
924+
return_ty.into()
925+
} else {
926+
continue;
927+
}
928+
} else {
929+
continue;
930+
}
931+
} else {
932+
term.skip_binder()
933+
};
921934

922935
if first {
923936
p!("<");
@@ -928,7 +941,7 @@ pub trait PrettyPrinter<'tcx>:
928941

929942
p!(write("{} = ", self.tcx().associated_item(assoc_item_def_id).name));
930943

931-
match term.skip_binder() {
944+
match term {
932945
Term::Ty(ty) => {
933946
p!(print(ty))
934947
}

src/test/ui/async-await/async-block-control-flow-static-semantics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async fn return_targets_async_block_not_async_fn() -> u8 {
2424
return 0u8;
2525
};
2626
let _: &dyn Future<Output = ()> = &block;
27-
//~^ ERROR type mismatch resolving `<impl Future as Future>::Output == ()`
27+
//~^ ERROR type mismatch resolving `<impl Future<Output = u8> as Future>::Output == ()`
2828
}
2929

3030
fn no_break_in_async_block() {

src/test/ui/async-await/async-block-control-flow-static-semantics.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ LL | |
3131
LL | | }
3232
| |_^ expected `u8`, found `()`
3333

34-
error[E0271]: type mismatch resolving `<impl Future as Future>::Output == ()`
34+
error[E0271]: type mismatch resolving `<impl Future<Output = u8> as Future>::Output == ()`
3535
--> $DIR/async-block-control-flow-static-semantics.rs:26:39
3636
|
3737
LL | let _: &dyn Future<Output = ()> = &block;
@@ -47,7 +47,7 @@ LL | fn return_targets_async_block_not_fn() -> u8 {
4747
| |
4848
| implicitly returns `()` as its body has no tail or `return` expression
4949

50-
error[E0271]: type mismatch resolving `<impl Future as Future>::Output == ()`
50+
error[E0271]: type mismatch resolving `<impl Future<Output = u8> as Future>::Output == ()`
5151
--> $DIR/async-block-control-flow-static-semantics.rs:17:39
5252
|
5353
LL | let _: &dyn Future<Output = ()> = &block;

src/test/ui/async-await/generator-desc.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
4646
| the expected opaque type
4747
| the found opaque type
4848
|
49-
= note: expected opaque type `impl Future` (`async` closure body)
50-
found opaque type `impl Future` (`async` closure body)
49+
= note: expected opaque type `impl Future<Output = ()>` (`async` closure body)
50+
found opaque type `impl Future<Output = ()>` (`async` closure body)
5151

5252
error: aborting due to 3 previous errors
5353

src/test/ui/async-await/issue-67252-unnamed-future.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: future cannot be sent between threads safely
44
LL | spawn(async {
55
| ^^^^^ future created by async block is not `Send`
66
|
7-
= help: within `impl Future`, the trait `Send` is not implemented for `*mut ()`
7+
= help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*mut ()`
88
note: future is not `Send` as this value is used across an await
99
--> $DIR/issue-67252-unnamed-future.rs:20:16
1010
|

src/test/ui/async-await/issue-68112.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ LL | require_send(send_fut);
4444
= note: required because of the requirements on the impl of `Send` for `Arc<RefCell<i32>>`
4545
= note: required because it appears within the type `[static generator@$DIR/issue-68112.rs:47:31: 47:36]`
4646
= note: required because it appears within the type `from_generator::GenFuture<[static generator@$DIR/issue-68112.rs:47:31: 47:36]>`
47-
= note: required because it appears within the type `impl Future`
47+
= note: required because it appears within the type `impl Future<Output = Arc<RefCell<i32>>>`
4848
= note: required because it appears within the type `impl Future<Output = Arc<RefCell<i32>>>`
4949
= note: required because it appears within the type `impl Future<Output = Arc<RefCell<i32>>>`
5050
= note: required because it appears within the type `{ResumeTy, impl Future<Output = Arc<RefCell<i32>>>, (), i32, Ready<i32>}`
5151
= note: required because it appears within the type `[static generator@$DIR/issue-68112.rs:55:26: 59:6]`
5252
= note: required because it appears within the type `from_generator::GenFuture<[static generator@$DIR/issue-68112.rs:55:26: 59:6]>`
53-
= note: required because it appears within the type `impl Future`
53+
= note: required because it appears within the type `impl Future<Output = ()>`
5454
note: required by a bound in `require_send`
5555
--> $DIR/issue-68112.rs:11:25
5656
|

src/test/ui/async-await/issues/issue-65436-raw-ptr-not-send.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: future cannot be sent between threads safely
44
LL | assert_send(async {
55
| ^^^^^^^^^^^ future created by async block is not `Send`
66
|
7-
= help: within `impl Future`, the trait `Send` is not implemented for `*const u8`
7+
= help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*const u8`
88
note: future is not `Send` as this value is used across an await
99
--> $DIR/issue-65436-raw-ptr-not-send.rs:14:35
1010
|

src/test/ui/async-await/partial-drop-partial-reinit.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LL | async fn foo() {
1414
= note: required because it appears within the type `{ResumeTy, (NotSend,), impl Future<Output = ()>, ()}`
1515
= note: required because it appears within the type `[static generator@$DIR/partial-drop-partial-reinit.rs:22:16: 27:2]`
1616
= note: required because it appears within the type `from_generator::GenFuture<[static generator@$DIR/partial-drop-partial-reinit.rs:22:16: 27:2]>`
17-
= note: required because it appears within the type `impl Future`
17+
= note: required because it appears within the type `impl Future<Output = ()>`
1818
= note: required because it appears within the type `impl Future<Output = ()>`
1919
note: required by a bound in `gimme_send`
2020
--> $DIR/partial-drop-partial-reinit.rs:10:18

src/test/ui/chalkify/bugs/async.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ note: required by a bound in `from_generator`
2828
LL | T: Generator<ResumeTy, Yield = ()>,
2929
| ^^^^^^^^^^ required by this bound in `from_generator`
3030

31-
error[E0280]: the requirement `<impl Future as Future>::Output == u32` is not satisfied
31+
error[E0280]: the requirement `<impl Future<Output = u32> as Future>::Output == u32` is not satisfied
3232
--> $DIR/async.rs:7:29
3333
|
3434
LL | async fn foo(x: u32) -> u32 {

src/test/ui/impl-trait/issue-55872-3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl<S> Bar for S {
1313
type E = impl std::marker::Copy;
1414
fn foo<T>() -> Self::E {
1515
async {}
16-
//~^ ERROR the trait bound `impl Future: Copy` is not satisfied [E0277]
16+
//~^ ERROR the trait bound `impl Future<Output = ()>: Copy` is not satisfied [E0277]
1717
}
1818
}
1919

src/test/ui/impl-trait/issue-55872-3.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0277]: the trait bound `impl Future: Copy` is not satisfied
1+
error[E0277]: the trait bound `impl Future<Output = ()>: Copy` is not satisfied
22
--> $DIR/issue-55872-3.rs:15:9
33
|
44
LL | async {}
5-
| ^^^^^^^^ the trait `Copy` is not implemented for `impl Future`
5+
| ^^^^^^^^ the trait `Copy` is not implemented for `impl Future<Output = ()>`
66

77
error: aborting due to previous error
88

src/test/ui/impl-trait/issues/issue-78722.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LL | let f: F = async { 1 };
1616
LL | }],
1717
| - value is dropped here
1818

19-
error[E0271]: type mismatch resolving `<impl Future as Future>::Output == u8`
19+
error[E0271]: type mismatch resolving `<impl Future<Output = ()> as Future>::Output == u8`
2020
--> $DIR/issue-78722.rs:10:13
2121
|
2222
LL | async {}

src/test/ui/pattern/non-structural-match-types.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: `[closure@$DIR/non-structural-match-types.rs:9:17: 9:22]` cannot be used
44
LL | const { || {} } => {},
55
| ^^^^^^^^^^^^^^^
66

7-
error: `impl Future` cannot be used in patterns
7+
error: `impl Future<Output = ()>` cannot be used in patterns
88
--> $DIR/non-structural-match-types.rs:12:9
99
|
1010
LL | const { async {} } => {},

0 commit comments

Comments
 (0)