Skip to content

Commit 8124b26

Browse files
committed
update region debug formatting
1 parent 13abc0a commit 8124b26

32 files changed

+194
-157
lines changed

Diff for: compiler/rustc_middle/src/ty/region.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,9 @@ pub struct EarlyParamRegion {
336336

337337
impl std::fmt::Debug for EarlyParamRegion {
338338
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
339-
write!(f, "{:?}, {}, {}", self.def_id, self.index, self.name)
339+
// FIXME(BoxyUwU): self.def_id goes first because of `erased-regions-in-hidden-ty.rs` being impossible to write
340+
// error annotations for otherwise. :). Ideally this would be `self.name, self.index, self.def_id`.
341+
write!(f, "{:?}_{}/#{}", self.def_id, self.name, self.index)
340342
}
341343
}
342344

@@ -381,13 +383,25 @@ pub enum BoundRegionKind {
381383
BrEnv,
382384
}
383385

384-
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, PartialOrd, Ord)]
386+
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, PartialOrd, Ord)]
385387
#[derive(HashStable)]
386388
pub struct BoundRegion {
387389
pub var: BoundVar,
388390
pub kind: BoundRegionKind,
389391
}
390392

393+
impl core::fmt::Debug for BoundRegion {
394+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
395+
match self.kind {
396+
BoundRegionKind::BrAnon => write!(f, "{:?}", self.var),
397+
BoundRegionKind::BrEnv => write!(f, "{:?}.Env", self.var),
398+
BoundRegionKind::BrNamed(def, symbol) => {
399+
write!(f, "{:?}.Named({:?}, {:?})", self.var, def, symbol)
400+
}
401+
}
402+
}
403+
}
404+
391405
impl BoundRegionKind {
392406
pub fn is_named(&self) -> bool {
393407
match *self {

Diff for: compiler/rustc_type_ir/src/region_kind.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -223,23 +223,27 @@ impl<I: Interner> DebugWithInfcx<I> for RegionKind<I> {
223223
f: &mut core::fmt::Formatter<'_>,
224224
) -> core::fmt::Result {
225225
match this.data {
226-
ReEarlyParam(data) => write!(f, "ReEarlyParam({data:?})"),
226+
ReEarlyParam(data) => write!(f, "{data:?}"),
227227

228228
ReBound(binder_id, bound_region) => {
229-
write!(f, "ReBound({binder_id:?}, {bound_region:?})")
229+
write!(f, "'")?;
230+
crate::debug_bound_var(f, *binder_id, bound_region)
230231
}
231232

232233
ReLateParam(fr) => write!(f, "{fr:?}"),
233234

234-
ReStatic => f.write_str("ReStatic"),
235+
ReStatic => f.write_str("'static"),
235236

236237
ReVar(vid) => write!(f, "{:?}", &this.wrap(vid)),
237238

238-
RePlaceholder(placeholder) => write!(f, "RePlaceholder({placeholder:?})"),
239+
RePlaceholder(placeholder) => write!(f, "{placeholder:?}"),
239240

240-
ReErased => f.write_str("ReErased"),
241+
// Use `'{erased}` as the output instead of `'erased` so that its more obviously distinct from
242+
// a `ReEarlyParam` named `'erased`. Technically that would print as `'erased/#IDX` so this is
243+
// not strictly necessary but *shrug*
244+
ReErased => f.write_str("'{erased}"),
241245

242-
ReError(_) => f.write_str("ReError"),
246+
ReError(_) => f.write_str("'{region error}"),
243247
}
244248
}
245249
}

Diff for: tests/mir-opt/issue_99325.main.built.after.32bit.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
| User Type Annotations
44
| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:13:16: 13:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5-
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [UnevaluatedConst { def: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}), args: [] }: &ReStatic [u8; 4_usize]], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5+
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [UnevaluatedConst { def: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}), args: [] }: &'static [u8; 4_usize]], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
66
|
77
fn main() -> () {
88
let mut _0: ();

Diff for: tests/mir-opt/issue_99325.main.built.after.64bit.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
| User Type Annotations
44
| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:13:16: 13:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5-
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [UnevaluatedConst { def: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}), args: [] }: &ReStatic [u8; 4_usize]], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5+
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [UnevaluatedConst { def: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}), args: [] }: &'static [u8; 4_usize]], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
66
|
77
fn main() -> () {
88
let mut _0: ();

Diff for: tests/ui/associated-types/substs-ppaux.normal.stderr

+42-36
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,73 @@
11
error[E0308]: mismatched types
2-
--> $DIR/substs-ppaux.rs:16:17
2+
--> $DIR/substs-ppaux.rs:23:17
33
|
4-
LL | fn bar<'a, T>() where T: 'a {}
5-
| --------------------------- associated function `bar` defined here
4+
LL | / fn bar<'a, T>()
5+
LL | | where
6+
LL | | T: 'a,
7+
| |______________- associated function `bar` defined here
68
...
7-
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>;
8-
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
9-
| |
10-
| expected due to this
9+
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>;
10+
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
11+
| |
12+
| expected due to this
1113
|
1214
= note: expected unit type `()`
1315
found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::bar::<'static, char>}`
1416
help: use parentheses to call this associated function
1517
|
16-
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>();
17-
| ++
18+
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>();
19+
| ++
1820

1921
error[E0308]: mismatched types
20-
--> $DIR/substs-ppaux.rs:25:17
22+
--> $DIR/substs-ppaux.rs:31:17
2123
|
22-
LL | fn bar<'a, T>() where T: 'a {}
23-
| --------------------------- associated function `bar` defined here
24+
LL | / fn bar<'a, T>()
25+
LL | | where
26+
LL | | T: 'a,
27+
| |______________- associated function `bar` defined here
2428
...
25-
LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>;
26-
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
27-
| |
28-
| expected due to this
29+
LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>;
30+
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
31+
| |
32+
| expected due to this
2933
|
3034
= note: expected unit type `()`
3135
found fn item `fn() {<i8 as Foo<'static, 'static>>::bar::<'static, char>}`
3236
help: use parentheses to call this associated function
3337
|
34-
LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>();
35-
| ++
38+
LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>();
39+
| ++
3640

3741
error[E0308]: mismatched types
38-
--> $DIR/substs-ppaux.rs:33:17
42+
--> $DIR/substs-ppaux.rs:39:17
3943
|
4044
LL | fn baz() {}
4145
| -------- associated function `baz` defined here
4246
...
43-
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz;
44-
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
47+
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz;
48+
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
4549
| |
4650
| expected due to this
4751
|
4852
= note: expected unit type `()`
4953
found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::baz}`
5054
help: use parentheses to call this associated function
5155
|
52-
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz();
53-
| ++
56+
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz();
57+
| ++
5458

5559
error[E0308]: mismatched types
56-
--> $DIR/substs-ppaux.rs:41:17
60+
--> $DIR/substs-ppaux.rs:47:17
5761
|
58-
LL | fn foo<'z>() where &'z (): Sized {
59-
| -------------------------------- function `foo` defined here
62+
LL | / fn foo<'z>()
63+
LL | | where
64+
LL | | &'z (): Sized,
65+
| |__________________- function `foo` defined here
6066
...
61-
LL | let x: () = foo::<'static>;
62-
| -- ^^^^^^^^^^^^^^ expected `()`, found fn item
63-
| |
64-
| expected due to this
67+
LL | let x: () = foo::<'static>;
68+
| -- ^^^^^^^^^^^^^^ expected `()`, found fn item
69+
| |
70+
| expected due to this
6571
|
6672
= note: expected unit type `()`
6773
found fn item `fn() {foo::<'static>}`
@@ -71,18 +77,18 @@ LL | let x: () = foo::<'static>();
7177
| ++
7278

7379
error[E0277]: the trait bound `str: Foo<'_, '_, u8>` is not satisfied
74-
--> $DIR/substs-ppaux.rs:49:6
80+
--> $DIR/substs-ppaux.rs:55:6
7581
|
7682
LL | <str as Foo<u8>>::bar;
7783
| ^^^ the trait `Sized` is not implemented for `str`, which is required by `str: Foo<'_, '_, u8>`
7884
|
7985
note: required for `str` to implement `Foo<'_, '_, u8>`
80-
--> $DIR/substs-ppaux.rs:11:17
86+
--> $DIR/substs-ppaux.rs:15:20
8187
|
82-
LL | impl<'a,'b,T,S> Foo<'a, 'b, S> for T {}
83-
| - ^^^^^^^^^^^^^^ ^
84-
| |
85-
| unsatisfied trait bound introduced here
88+
LL | impl<'a, 'b, T, S> Foo<'a, 'b, S> for T {}
89+
| - ^^^^^^^^^^^^^^ ^
90+
| |
91+
| unsatisfied trait bound introduced here
8692

8793
error: aborting due to 5 previous errors
8894

Diff for: tests/ui/associated-types/substs-ppaux.rs

+18-12
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,51 @@
33
//
44
//@[verbose] compile-flags: -Z verbose-internals
55

6-
trait Foo<'b, 'c, S=u32> {
7-
fn bar<'a, T>() where T: 'a {}
6+
trait Foo<'b, 'c, S = u32> {
7+
fn bar<'a, T>()
8+
where
9+
T: 'a,
10+
{
11+
}
812
fn baz() {}
913
}
1014

11-
impl<'a,'b,T,S> Foo<'a, 'b, S> for T {}
15+
impl<'a, 'b, T, S> Foo<'a, 'b, S> for T {}
1216

1317
fn main() {}
1418

15-
fn foo<'z>() where &'z (): Sized {
16-
let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>;
19+
fn foo<'z>()
20+
where
21+
&'z (): Sized,
22+
{
23+
let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>;
1724
//[verbose]~^ ERROR mismatched types
1825
//[verbose]~| expected unit type `()`
19-
//[verbose]~| found fn item `fn() {<i8 as Foo<ReStatic, ReStatic, u8>>::bar::<ReStatic, char>}`
26+
//[verbose]~| found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::bar::<'static, char>}`
2027
//[normal]~^^^^ ERROR mismatched types
2128
//[normal]~| expected unit type `()`
2229
//[normal]~| found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::bar::<'static, char>}`
2330

24-
25-
let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>;
31+
let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>;
2632
//[verbose]~^ ERROR mismatched types
2733
//[verbose]~| expected unit type `()`
28-
//[verbose]~| found fn item `fn() {<i8 as Foo<ReStatic, ReStatic>>::bar::<ReStatic, char>}`
34+
//[verbose]~| found fn item `fn() {<i8 as Foo<'static, 'static>>::bar::<'static, char>}`
2935
//[normal]~^^^^ ERROR mismatched types
3036
//[normal]~| expected unit type `()`
3137
//[normal]~| found fn item `fn() {<i8 as Foo<'static, 'static>>::bar::<'static, char>}`
3238

33-
let x: () = <i8 as Foo<'static, 'static, u8>>::baz;
39+
let x: () = <i8 as Foo<'static, 'static, u8>>::baz;
3440
//[verbose]~^ ERROR mismatched types
3541
//[verbose]~| expected unit type `()`
36-
//[verbose]~| found fn item `fn() {<i8 as Foo<ReStatic, ReStatic, u8>>::baz}`
42+
//[verbose]~| found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::baz}`
3743
//[normal]~^^^^ ERROR mismatched types
3844
//[normal]~| expected unit type `()`
3945
//[normal]~| found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::baz}`
4046

4147
let x: () = foo::<'static>;
4248
//[verbose]~^ ERROR mismatched types
4349
//[verbose]~| expected unit type `()`
44-
//[verbose]~| found fn item `fn() {foo::<ReStatic>}`
50+
//[verbose]~| found fn item `fn() {foo::<'static>}`
4551
//[normal]~^^^^ ERROR mismatched types
4652
//[normal]~| expected unit type `()`
4753
//[normal]~| found fn item `fn() {foo::<'static>}`

0 commit comments

Comments
 (0)