Skip to content

Commit 2a79ee6

Browse files
committed
In pretty_print_type(), print async fn futures' paths instead of spans.
This makes `-Zprint-type-sizes`'s output easier to read, because the name of an `async fn` is more immediately recognizable than its span. I also deleted the comment "FIXME(eddyb) should use `def_span`." because it appears to have already been fixed by commit 67727aa.
1 parent 85e449a commit 2a79ee6

File tree

6 files changed

+39
-31
lines changed

6 files changed

+39
-31
lines changed

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

+13-5
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
804804
}
805805
ty::Str => p!("str"),
806806
ty::Coroutine(did, args) => {
807-
p!(write("{{"));
807+
p!("{{");
808808
let coroutine_kind = self.tcx().coroutine_kind(did).unwrap();
809809
let should_print_movability = self.should_print_verbose()
810810
|| matches!(coroutine_kind, hir::CoroutineKind::Coroutine(_));
@@ -818,17 +818,25 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
818818

819819
if !self.should_print_verbose() {
820820
p!(write("{}", coroutine_kind));
821-
// FIXME(eddyb) should use `def_span`.
822-
if let Some(did) = did.as_local() {
823-
let span = self.tcx().def_span(did);
821+
if coroutine_kind.is_fn_like() {
822+
// If we are printing an `async fn` coroutine type, then give the path
823+
// of the fn, instead of its span, because that will in most cases be
824+
// more helpful for the reader than just a source location.
825+
//
826+
// This will look like:
827+
// {async fn body some_module::some_fn}
828+
let did_of_the_fn_item = self.tcx().parent(did);
829+
p!(" ", print_def_path(did_of_the_fn_item, args));
830+
} else if let Some(local_did) = did.as_local() {
831+
let span = self.tcx().def_span(local_did);
824832
p!(write(
825833
"@{}",
826834
// This may end up in stderr diagnostics but it may also be emitted
827835
// into MIR. Hence we use the remapped path if available
828836
self.tcx().sess.source_map().span_to_embeddable_string(span)
829837
));
830838
} else {
831-
p!(write("@"), print_def_path(did, args));
839+
p!("@", print_def_path(did, args));
832840
}
833841
} else {
834842
p!(print_def_path(did, args));

tests/ui/async-await/future-sizes/async-awaiting-fut.stdout

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
print-type-size type: `{async fn body@$DIR/async-awaiting-fut.rs:21:21: 24:2}`: 3078 bytes, alignment: 1 bytes
1+
print-type-size type: `{async fn body test}`: 3078 bytes, alignment: 1 bytes
22
print-type-size discriminant: 1 bytes
33
print-type-size variant `Unresumed`: 0 bytes
44
print-type-size variant `Suspend0`: 3077 bytes
55
print-type-size local `.__awaitee`: 3077 bytes
66
print-type-size variant `Returned`: 0 bytes
77
print-type-size variant `Panicked`: 0 bytes
8-
print-type-size type: `std::mem::ManuallyDrop<{async fn body@$DIR/async-awaiting-fut.rs:10:64: 19:2}>`: 3077 bytes, alignment: 1 bytes
8+
print-type-size type: `std::mem::ManuallyDrop<{async fn body calls_fut<{async fn body big_fut}>}>`: 3077 bytes, alignment: 1 bytes
99
print-type-size field `.value`: 3077 bytes
10-
print-type-size type: `std::mem::MaybeUninit<{async fn body@$DIR/async-awaiting-fut.rs:10:64: 19:2}>`: 3077 bytes, alignment: 1 bytes
10+
print-type-size type: `std::mem::MaybeUninit<{async fn body calls_fut<{async fn body big_fut}>}>`: 3077 bytes, alignment: 1 bytes
1111
print-type-size variant `MaybeUninit`: 3077 bytes
1212
print-type-size field `.uninit`: 0 bytes
1313
print-type-size field `.value`: 3077 bytes
14-
print-type-size type: `{async fn body@$DIR/async-awaiting-fut.rs:10:64: 19:2}`: 3077 bytes, alignment: 1 bytes
14+
print-type-size type: `{async fn body calls_fut<{async fn body big_fut}>}`: 3077 bytes, alignment: 1 bytes
1515
print-type-size discriminant: 1 bytes
1616
print-type-size variant `Unresumed`: 1025 bytes
1717
print-type-size upvar `.fut`: 1025 bytes, offset: 0 bytes, alignment: 1 bytes
@@ -36,13 +36,13 @@ print-type-size variant `Returned`: 1025 bytes
3636
print-type-size upvar `.fut`: 1025 bytes, offset: 0 bytes, alignment: 1 bytes
3737
print-type-size variant `Panicked`: 1025 bytes
3838
print-type-size upvar `.fut`: 1025 bytes, offset: 0 bytes, alignment: 1 bytes
39-
print-type-size type: `std::mem::ManuallyDrop<{async fn body@$DIR/async-awaiting-fut.rs:8:35: 8:37}>`: 1025 bytes, alignment: 1 bytes
39+
print-type-size type: `std::mem::ManuallyDrop<{async fn body big_fut}>`: 1025 bytes, alignment: 1 bytes
4040
print-type-size field `.value`: 1025 bytes
41-
print-type-size type: `std::mem::MaybeUninit<{async fn body@$DIR/async-awaiting-fut.rs:8:35: 8:37}>`: 1025 bytes, alignment: 1 bytes
41+
print-type-size type: `std::mem::MaybeUninit<{async fn body big_fut}>`: 1025 bytes, alignment: 1 bytes
4242
print-type-size variant `MaybeUninit`: 1025 bytes
4343
print-type-size field `.uninit`: 0 bytes
4444
print-type-size field `.value`: 1025 bytes
45-
print-type-size type: `{async fn body@$DIR/async-awaiting-fut.rs:8:35: 8:37}`: 1025 bytes, alignment: 1 bytes
45+
print-type-size type: `{async fn body big_fut}`: 1025 bytes, alignment: 1 bytes
4646
print-type-size discriminant: 1 bytes
4747
print-type-size variant `Unresumed`: 1024 bytes
4848
print-type-size upvar `.arg`: 1024 bytes
@@ -52,13 +52,13 @@ print-type-size variant `Panicked`: 1024 bytes
5252
print-type-size upvar `.arg`: 1024 bytes
5353
print-type-size type: `std::mem::ManuallyDrop<bool>`: 1 bytes, alignment: 1 bytes
5454
print-type-size field `.value`: 1 bytes
55-
print-type-size type: `std::mem::ManuallyDrop<{async fn body@$DIR/async-awaiting-fut.rs:6:17: 6:19}>`: 1 bytes, alignment: 1 bytes
55+
print-type-size type: `std::mem::ManuallyDrop<{async fn body wait}>`: 1 bytes, alignment: 1 bytes
5656
print-type-size field `.value`: 1 bytes
5757
print-type-size type: `std::mem::MaybeUninit<bool>`: 1 bytes, alignment: 1 bytes
5858
print-type-size variant `MaybeUninit`: 1 bytes
5959
print-type-size field `.uninit`: 0 bytes
6060
print-type-size field `.value`: 1 bytes
61-
print-type-size type: `std::mem::MaybeUninit<{async fn body@$DIR/async-awaiting-fut.rs:6:17: 6:19}>`: 1 bytes, alignment: 1 bytes
61+
print-type-size type: `std::mem::MaybeUninit<{async fn body wait}>`: 1 bytes, alignment: 1 bytes
6262
print-type-size variant `MaybeUninit`: 1 bytes
6363
print-type-size field `.uninit`: 0 bytes
6464
print-type-size field `.value`: 1 bytes
@@ -67,7 +67,7 @@ print-type-size discriminant: 1 bytes
6767
print-type-size variant `Ready`: 0 bytes
6868
print-type-size field `.0`: 0 bytes
6969
print-type-size variant `Pending`: 0 bytes
70-
print-type-size type: `{async fn body@$DIR/async-awaiting-fut.rs:6:17: 6:19}`: 1 bytes, alignment: 1 bytes
70+
print-type-size type: `{async fn body wait}`: 1 bytes, alignment: 1 bytes
7171
print-type-size discriminant: 1 bytes
7272
print-type-size variant `Unresumed`: 0 bytes
7373
print-type-size variant `Returned`: 0 bytes

tests/ui/async-await/future-sizes/large-arg.stdout

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
print-type-size type: `{async fn body@$DIR/large-arg.rs:6:21: 8:2}`: 3076 bytes, alignment: 1 bytes
1+
print-type-size type: `{async fn body test}`: 3076 bytes, alignment: 1 bytes
22
print-type-size discriminant: 1 bytes
33
print-type-size variant `Unresumed`: 0 bytes
44
print-type-size variant `Suspend0`: 3075 bytes
55
print-type-size local `.__awaitee`: 3075 bytes
66
print-type-size variant `Returned`: 0 bytes
77
print-type-size variant `Panicked`: 0 bytes
8-
print-type-size type: `std::mem::ManuallyDrop<{async fn body@$DIR/large-arg.rs:10:30: 12:2}>`: 3075 bytes, alignment: 1 bytes
8+
print-type-size type: `std::mem::ManuallyDrop<{async fn body a<[u8; 1024]>}>`: 3075 bytes, alignment: 1 bytes
99
print-type-size field `.value`: 3075 bytes
10-
print-type-size type: `std::mem::MaybeUninit<{async fn body@$DIR/large-arg.rs:10:30: 12:2}>`: 3075 bytes, alignment: 1 bytes
10+
print-type-size type: `std::mem::MaybeUninit<{async fn body a<[u8; 1024]>}>`: 3075 bytes, alignment: 1 bytes
1111
print-type-size variant `MaybeUninit`: 3075 bytes
1212
print-type-size field `.uninit`: 0 bytes
1313
print-type-size field `.value`: 3075 bytes
14-
print-type-size type: `{async fn body@$DIR/large-arg.rs:10:30: 12:2}`: 3075 bytes, alignment: 1 bytes
14+
print-type-size type: `{async fn body a<[u8; 1024]>}`: 3075 bytes, alignment: 1 bytes
1515
print-type-size discriminant: 1 bytes
1616
print-type-size variant `Unresumed`: 1024 bytes
1717
print-type-size upvar `.t`: 1024 bytes
@@ -22,13 +22,13 @@ print-type-size variant `Returned`: 1024 bytes
2222
print-type-size upvar `.t`: 1024 bytes
2323
print-type-size variant `Panicked`: 1024 bytes
2424
print-type-size upvar `.t`: 1024 bytes
25-
print-type-size type: `std::mem::ManuallyDrop<{async fn body@$DIR/large-arg.rs:13:26: 15:2}>`: 2050 bytes, alignment: 1 bytes
25+
print-type-size type: `std::mem::ManuallyDrop<{async fn body b<[u8; 1024]>}>`: 2050 bytes, alignment: 1 bytes
2626
print-type-size field `.value`: 2050 bytes
27-
print-type-size type: `std::mem::MaybeUninit<{async fn body@$DIR/large-arg.rs:13:26: 15:2}>`: 2050 bytes, alignment: 1 bytes
27+
print-type-size type: `std::mem::MaybeUninit<{async fn body b<[u8; 1024]>}>`: 2050 bytes, alignment: 1 bytes
2828
print-type-size variant `MaybeUninit`: 2050 bytes
2929
print-type-size field `.uninit`: 0 bytes
3030
print-type-size field `.value`: 2050 bytes
31-
print-type-size type: `{async fn body@$DIR/large-arg.rs:13:26: 15:2}`: 2050 bytes, alignment: 1 bytes
31+
print-type-size type: `{async fn body b<[u8; 1024]>}`: 2050 bytes, alignment: 1 bytes
3232
print-type-size discriminant: 1 bytes
3333
print-type-size variant `Unresumed`: 1024 bytes
3434
print-type-size upvar `.t`: 1024 bytes
@@ -39,9 +39,9 @@ print-type-size variant `Returned`: 1024 bytes
3939
print-type-size upvar `.t`: 1024 bytes
4040
print-type-size variant `Panicked`: 1024 bytes
4141
print-type-size upvar `.t`: 1024 bytes
42-
print-type-size type: `std::mem::ManuallyDrop<{async fn body@$DIR/large-arg.rs:16:26: 18:2}>`: 1025 bytes, alignment: 1 bytes
42+
print-type-size type: `std::mem::ManuallyDrop<{async fn body c<[u8; 1024]>}>`: 1025 bytes, alignment: 1 bytes
4343
print-type-size field `.value`: 1025 bytes
44-
print-type-size type: `std::mem::MaybeUninit<{async fn body@$DIR/large-arg.rs:16:26: 18:2}>`: 1025 bytes, alignment: 1 bytes
44+
print-type-size type: `std::mem::MaybeUninit<{async fn body c<[u8; 1024]>}>`: 1025 bytes, alignment: 1 bytes
4545
print-type-size variant `MaybeUninit`: 1025 bytes
4646
print-type-size field `.uninit`: 0 bytes
4747
print-type-size field `.value`: 1025 bytes
@@ -50,7 +50,7 @@ print-type-size discriminant: 1 bytes
5050
print-type-size variant `Ready`: 1024 bytes
5151
print-type-size field `.0`: 1024 bytes
5252
print-type-size variant `Pending`: 0 bytes
53-
print-type-size type: `{async fn body@$DIR/large-arg.rs:16:26: 18:2}`: 1025 bytes, alignment: 1 bytes
53+
print-type-size type: `{async fn body c<[u8; 1024]>}`: 1025 bytes, alignment: 1 bytes
5454
print-type-size discriminant: 1 bytes
5555
print-type-size variant `Unresumed`: 1024 bytes
5656
print-type-size upvar `.t`: 1024 bytes
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
error: the compiler unexpectedly panicked. this is a bug.
22

33
query stack during panic:
4-
#0 [evaluate_obligation] evaluating trait selection obligation `for<'a> {async fn body@$DIR/future.rs:33:35: 35:2}: core::future::future::Future`
4+
#0 [evaluate_obligation] evaluating trait selection obligation `for<'a> {async fn body strlen}: core::future::future::Future`
55
#1 [codegen_select_candidate] computing candidate for `<strlen as Trait>`
66
end of query stack

tests/ui/print_type_sizes/async.stdout

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
print-type-size type: `{async fn body@$DIR/async.rs:10:36: 13:2}`: 16386 bytes, alignment: 1 bytes
1+
print-type-size type: `{async fn body test}`: 16386 bytes, alignment: 1 bytes
22
print-type-size discriminant: 1 bytes
33
print-type-size variant `Unresumed`: 8192 bytes
44
print-type-size upvar `.arg`: 8192 bytes
@@ -16,9 +16,9 @@ print-type-size type: `std::mem::MaybeUninit<[u8; 8192]>`: 8192 bytes, alignment
1616
print-type-size variant `MaybeUninit`: 8192 bytes
1717
print-type-size field `.uninit`: 0 bytes
1818
print-type-size field `.value`: 8192 bytes
19-
print-type-size type: `std::mem::ManuallyDrop<{async fn body@$DIR/async.rs:8:17: 8:19}>`: 1 bytes, alignment: 1 bytes
19+
print-type-size type: `std::mem::ManuallyDrop<{async fn body wait}>`: 1 bytes, alignment: 1 bytes
2020
print-type-size field `.value`: 1 bytes
21-
print-type-size type: `std::mem::MaybeUninit<{async fn body@$DIR/async.rs:8:17: 8:19}>`: 1 bytes, alignment: 1 bytes
21+
print-type-size type: `std::mem::MaybeUninit<{async fn body wait}>`: 1 bytes, alignment: 1 bytes
2222
print-type-size variant `MaybeUninit`: 1 bytes
2323
print-type-size field `.uninit`: 0 bytes
2424
print-type-size field `.value`: 1 bytes
@@ -27,7 +27,7 @@ print-type-size discriminant: 1 bytes
2727
print-type-size variant `Ready`: 0 bytes
2828
print-type-size field `.0`: 0 bytes
2929
print-type-size variant `Pending`: 0 bytes
30-
print-type-size type: `{async fn body@$DIR/async.rs:8:17: 8:19}`: 1 bytes, alignment: 1 bytes
30+
print-type-size type: `{async fn body wait}`: 1 bytes, alignment: 1 bytes
3131
print-type-size discriminant: 1 bytes
3232
print-type-size variant `Unresumed`: 0 bytes
3333
print-type-size variant `Returned`: 0 bytes

tests/ui/type-alias-impl-trait/hkl_forbidden4.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error: concrete type differs from previous defining opaque type use
1010
--> $DIR/hkl_forbidden4.rs:13:1
1111
|
1212
LL | async fn operation(_: &mut ()) -> () {
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `FutNothing<'_>`, got `{async fn body@$DIR/hkl_forbidden4.rs:13:38: 16:2}`
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `FutNothing<'_>`, got `{async fn body operation}`
1414
|
1515
note: previous use here
1616
--> $DIR/hkl_forbidden4.rs:15:5

0 commit comments

Comments
 (0)