Skip to content

Commit ef31e73

Browse files
authored
Unrolled build for rust-lang#120896
Rollup merge of rust-lang#120896 - compiler-errors:coro-closure-kind, r=oli-obk Print kind of coroutine closure Make sure that we print "async closure" when we have an async closure, rather than calling it generically a ["coroutine-closure"](rust-lang#120361). Fixes rust-lang#120886 r? oli-obk
2 parents 980cf08 + 86ddb53 commit ef31e73

9 files changed

+29
-12
lines changed

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

+18-1
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,24 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
877877
ty::CoroutineClosure(did, args) => {
878878
p!(write("{{"));
879879
if !self.should_print_verbose() {
880-
p!(write("coroutine-closure"));
880+
match self.tcx().coroutine_kind(self.tcx().coroutine_for_closure(did)).unwrap()
881+
{
882+
hir::CoroutineKind::Desugared(
883+
hir::CoroutineDesugaring::Async,
884+
hir::CoroutineSource::Closure,
885+
) => p!("async closure"),
886+
hir::CoroutineKind::Desugared(
887+
hir::CoroutineDesugaring::AsyncGen,
888+
hir::CoroutineSource::Closure,
889+
) => p!("async gen closure"),
890+
hir::CoroutineKind::Desugared(
891+
hir::CoroutineDesugaring::Gen,
892+
hir::CoroutineSource::Closure,
893+
) => p!("gen closure"),
894+
_ => unreachable!(
895+
"coroutine from coroutine-closure should have CoroutineSource::Closure"
896+
),
897+
}
881898
// FIXME(eddyb) should use `def_span`.
882899
if let Some(did) = did.as_local() {
883900
if self.tcx().sess.opts.unstable_opts.span_free_formats {

tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_move.0.panic-abort.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// MIR for `main::{closure#0}::{closure#0}` 0 coroutine_closure_by_move
22

3-
fn main::{closure#0}::{closure#0}(_1: {coroutine-closure@$DIR/async_closure_shims.rs:39:33: 39:52}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10} {
3+
fn main::{closure#0}::{closure#0}(_1: {async closure@$DIR/async_closure_shims.rs:39:33: 39:52}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10} {
44
let mut _0: {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10};
55

66
bb0: {

tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_move.0.panic-unwind.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// MIR for `main::{closure#0}::{closure#0}` 0 coroutine_closure_by_move
22

3-
fn main::{closure#0}::{closure#0}(_1: {coroutine-closure@$DIR/async_closure_shims.rs:39:33: 39:52}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10} {
3+
fn main::{closure#0}::{closure#0}(_1: {async closure@$DIR/async_closure_shims.rs:39:33: 39:52}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10} {
44
let mut _0: {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10};
55

66
bb0: {

tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_mut.0.panic-abort.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// MIR for `main::{closure#0}::{closure#0}` 0 coroutine_closure_by_mut
22

3-
fn main::{closure#0}::{closure#0}(_1: &mut {coroutine-closure@$DIR/async_closure_shims.rs:39:33: 39:52}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10} {
3+
fn main::{closure#0}::{closure#0}(_1: &mut {async closure@$DIR/async_closure_shims.rs:39:33: 39:52}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10} {
44
debug a => _2;
55
debug b => ((*_1).0: i32);
66
let mut _0: {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10};

tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_mut.0.panic-unwind.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// MIR for `main::{closure#0}::{closure#0}` 0 coroutine_closure_by_mut
22

3-
fn main::{closure#0}::{closure#0}(_1: &mut {coroutine-closure@$DIR/async_closure_shims.rs:39:33: 39:52}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10} {
3+
fn main::{closure#0}::{closure#0}(_1: &mut {async closure@$DIR/async_closure_shims.rs:39:33: 39:52}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10} {
44
debug a => _2;
55
debug b => ((*_1).0: i32);
66
let mut _0: {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10};

tests/ui/async-await/async-closures/is-not-fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
fn main() {
66
fn needs_fn(x: impl FnOnce()) {}
77
needs_fn(async || {});
8-
//~^ ERROR expected `{coroutine-closure@is-not-fn.rs:7:14}` to be a closure that returns `()`
8+
//~^ ERROR expected `{async closure@is-not-fn.rs:7:14}` to be a closure that returns `()`
99
}

tests/ui/async-await/async-closures/is-not-fn.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0271]: expected `{coroutine-closure@is-not-fn.rs:7:14}` to be a closure that returns `()`, but it returns `{async closure body@$DIR/is-not-fn.rs:7:23: 7:25}`
1+
error[E0271]: expected `{async closure@is-not-fn.rs:7:14}` to be a closure that returns `()`, but it returns `{async closure body@$DIR/is-not-fn.rs:7:23: 7:25}`
22
--> $DIR/is-not-fn.rs:7:14
33
|
44
LL | needs_fn(async || {});

tests/ui/async-await/async-closures/move-consuming-capture.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0382]: use of moved value: `x`
22
--> $DIR/move-consuming-capture.rs:17:9
33
|
44
LL | let x = async move || {
5-
| - move occurs because `x` has type `{coroutine-closure@$DIR/move-consuming-capture.rs:13:17: 13:30}`, which does not implement the `Copy` trait
5+
| - move occurs because `x` has type `{async closure@$DIR/move-consuming-capture.rs:13:17: 13:30}`, which does not implement the `Copy` trait
66
...
77
LL | x().await;
88
| --- `x` moved due to this method call

tests/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ help: use parentheses to call this function
1818
LL | bar(foo());
1919
| ++
2020

21-
error[E0277]: `{coroutine-closure@$DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:11:25: 11:33}` is not a future
21+
error[E0277]: `{async closure@$DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:11:25: 11:33}` is not a future
2222
--> $DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:12:9
2323
|
2424
LL | bar(async_closure);
25-
| --- ^^^^^^^^^^^^^ `{coroutine-closure@$DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:11:25: 11:33}` is not a future
25+
| --- ^^^^^^^^^^^^^ `{async closure@$DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:11:25: 11:33}` is not a future
2626
| |
2727
| required by a bound introduced by this call
2828
|
29-
= help: the trait `Future` is not implemented for `{coroutine-closure@$DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:11:25: 11:33}`
30-
= note: {coroutine-closure@$DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:11:25: 11:33} must be a future or must implement `IntoFuture` to be awaited
29+
= help: the trait `Future` is not implemented for `{async closure@$DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:11:25: 11:33}`
30+
= note: {async closure@$DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:11:25: 11:33} must be a future or must implement `IntoFuture` to be awaited
3131
note: required by a bound in `bar`
3232
--> $DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:7:16
3333
|

0 commit comments

Comments
 (0)