Skip to content

Commit 20ecbf5

Browse files
committed
Make verbose print of regions a bit more compact.
1 parent 43dd3d5 commit 20ecbf5

31 files changed

+129
-132
lines changed

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,7 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
14171417
/// identified by both a universe, as well as a name residing within that universe. Distinct bound
14181418
/// regions/types/consts within the same universe simply have an unknown relationship to one
14191419
/// another.
1420-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
1420+
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
14211421
#[derive(HashStable, TyEncodable, TyDecodable)]
14221422
pub struct Placeholder<T> {
14231423
pub universe: UniverseIndex,

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

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,32 +2218,27 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
22182218
let regions: Vec<_> = value
22192219
.bound_vars()
22202220
.into_iter()
2221-
.map(|var| {
2221+
.enumerate()
2222+
.map(|(index, var)| {
22222223
let ty::BoundVariableKind::Region(var) = var else {
2223-
// This doesn't really matter because it doesn't get used,
2224-
// it's just an empty value
2225-
return ty::BrAnon(0);
2226-
};
2227-
match var {
2224+
// This doesn't really matter because it doesn't get used,
2225+
// it's just an empty value
2226+
return ty::BrAnon(0);
2227+
};
2228+
start_or_continue(&mut self, "for<", ", ");
2229+
let (def_id, name) = match var {
22282230
ty::BrAnon(_) | ty::BrEnv => {
2229-
start_or_continue(&mut self, "for<", ", ");
22302231
let name = next_name(&self);
2231-
debug!(?name);
2232-
do_continue(&mut self, name);
2233-
ty::BrNamed(CRATE_DEF_ID.to_def_id(), name)
2232+
(CRATE_DEF_ID.to_def_id(), name)
22342233
}
22352234
ty::BrNamed(def_id, kw::UnderscoreLifetime) => {
2236-
start_or_continue(&mut self, "for<", ", ");
22372235
let name = next_name(&self);
2238-
do_continue(&mut self, name);
2239-
ty::BrNamed(def_id, name)
2240-
}
2241-
ty::BrNamed(def_id, name) => {
2242-
start_or_continue(&mut self, "for<", ", ");
2243-
do_continue(&mut self, name);
2244-
ty::BrNamed(def_id, name)
2236+
(def_id, name)
22452237
}
2246-
}
2238+
ty::BrNamed(def_id, name) => (def_id, name),
2239+
};
2240+
let _ = write!(&mut self, "{}^{}", name, index);
2241+
ty::BrNamed(def_id, name)
22472242
})
22482243
.collect();
22492244
start_or_continue(&mut self, "", "> ");

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::ty::{self, InferConst, Lift, Term, TermKind, Ty, TyCtxt};
1111
use rustc_data_structures::functor::IdFunctor;
1212
use rustc_hir::def::Namespace;
1313
use rustc_index::vec::{Idx, IndexVec};
14+
use rustc_span::symbol::kw;
1415

1516
use std::fmt;
1617
use std::mem::ManuallyDrop;
@@ -65,25 +66,47 @@ impl<'tcx> fmt::Debug for ty::adjustment::Adjustment<'tcx> {
6566
}
6667
}
6768

69+
impl fmt::Debug for ty::EarlyBoundRegion {
70+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
71+
if self.name != kw::Empty && self.name != kw::UnderscoreLifetime {
72+
write!(f, "{}/{}", self.name, self.index)
73+
} else {
74+
write!(f, "BrNamed({:?})/{}", self.def_id, self.index)
75+
}
76+
}
77+
}
78+
79+
impl fmt::Debug for ty::BoundRegion {
80+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
81+
write!(f, "{:?}^{:?}", self.kind, self.var)
82+
}
83+
}
84+
6885
impl fmt::Debug for ty::BoundRegionKind {
6986
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7087
match *self {
71-
ty::BrAnon(n) => write!(f, "BrAnon({:?})", n),
88+
ty::BrAnon(n) => write!(f, "'{}", n),
7289
ty::BrNamed(did, name) => {
73-
if did.is_crate_root() {
74-
write!(f, "BrNamed({})", name)
90+
if name != kw::Empty && name != kw::UnderscoreLifetime {
91+
write!(f, "{}", name)
7592
} else {
76-
write!(f, "BrNamed({:?}, {})", did, name)
93+
write!(f, "BrNamed({:?})", did)
7794
}
7895
}
79-
ty::BrEnv => write!(f, "BrEnv"),
96+
ty::BrEnv => write!(f, "'env"),
8097
}
8198
}
8299
}
83100

84101
impl fmt::Debug for ty::FreeRegion {
85102
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
86-
write!(f, "ReFree({:?}, {:?})", self.scope, self.bound_region)
103+
write!(f, "ReFree({:?}, {:?})", self.bound_region, self.scope)
104+
}
105+
}
106+
107+
impl<T: fmt::Debug> fmt::Debug for ty::Placeholder<T> {
108+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
109+
write!(f, "Placeholder({:?}, {:?})", self.name, self.universe)
87110
}
88111
}
89112

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub enum BoundRegionKind {
7171
BrEnv,
7272
}
7373

74-
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, PartialOrd, Ord)]
74+
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, PartialOrd, Ord)]
7575
#[derive(HashStable)]
7676
pub struct BoundRegion {
7777
pub var: BoundVar,
@@ -1329,12 +1329,6 @@ pub struct EarlyBoundRegion {
13291329
pub name: Symbol,
13301330
}
13311331

1332-
impl fmt::Debug for EarlyBoundRegion {
1333-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1334-
write!(f, "{}, {}", self.index, self.name)
1335-
}
1336-
}
1337-
13381332
/// A **`const`** **v**ariable **ID**.
13391333
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
13401334
#[derive(HashStable, TyEncodable, TyDecodable)]

compiler/rustc_type_ir/src/sty.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,21 +1217,19 @@ impl<I: Interner> hash::Hash for RegionKind<I> {
12171217
impl<I: Interner> fmt::Debug for RegionKind<I> {
12181218
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12191219
match self {
1220-
ReEarlyBound(ref data) => write!(f, "ReEarlyBound({:?})", data),
1221-
1222-
ReLateBound(binder_id, ref bound_region) => {
1223-
write!(f, "ReLateBound({:?}, {:?})", binder_id, bound_region)
1220+
ReEarlyBound(ref data) => write!(f, "{:?}", data),
1221+
ReLateBound(debruijn, ref bound_region) => {
1222+
if *debruijn == super::INNERMOST {
1223+
write!(f, "{:?}", bound_region)
1224+
} else {
1225+
write!(f, "{:?}_{}", bound_region, debruijn.as_u32())
1226+
}
12241227
}
1225-
12261228
ReFree(ref fr) => fr.fmt(f),
1227-
1228-
ReStatic => write!(f, "ReStatic"),
1229-
12301229
ReVar(ref vid) => vid.fmt(f),
1231-
1232-
RePlaceholder(placeholder) => write!(f, "RePlaceholder({:?})", placeholder),
1233-
1234-
ReErased => write!(f, "ReErased"),
1230+
RePlaceholder(placeholder) => write!(f, "Re{:?}", placeholder),
1231+
ReStatic => write!(f, "'static"),
1232+
ReErased => write!(f, "'erased"),
12351233
}
12361234
}
12371235
}

src/test/ui/associated-types/substs-ppaux.normal.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>();
1717
| ++
1818

1919
error[E0308]: mismatched types
20-
--> $DIR/substs-ppaux.rs:25:17
20+
--> $DIR/substs-ppaux.rs:22:17
2121
|
2222
LL | fn bar<'a, T>() where T: 'a {}
2323
| --------------------------- fn() {<i8 as Foo<'static, 'static>>::bar::<'static, char>} defined here
@@ -35,7 +35,7 @@ LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>()
3535
| ++
3636

3737
error[E0308]: mismatched types
38-
--> $DIR/substs-ppaux.rs:33:17
38+
--> $DIR/substs-ppaux.rs:27:17
3939
|
4040
LL | fn baz() {}
4141
| -------- fn() {<i8 as Foo<'static, 'static, u8>>::baz} defined here
@@ -53,7 +53,7 @@ LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz();
5353
| ++
5454

5555
error[E0308]: mismatched types
56-
--> $DIR/substs-ppaux.rs:41:17
56+
--> $DIR/substs-ppaux.rs:32:17
5757
|
5858
LL | fn foo<'z>() where &'z (): Sized {
5959
| -------------------------------- fn() {foo::<'static>} defined here
@@ -71,7 +71,7 @@ LL | let x: () = foo::<'static>();
7171
| ++
7272

7373
error[E0277]: the size for values of type `str` cannot be known at compilation time
74-
--> $DIR/substs-ppaux.rs:49:5
74+
--> $DIR/substs-ppaux.rs:37:5
7575
|
7676
LL | <str as Foo<u8>>::bar;
7777
| ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time

src/test/ui/associated-types/substs-ppaux.rs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,26 @@ fn main() {}
1414

1515
fn foo<'z>() where &'z (): Sized {
1616
let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>;
17-
//[verbose]~^ ERROR mismatched types
18-
//[verbose]~| expected unit type `()`
19-
//[verbose]~| found fn item `fn() {<i8 as Foo<ReStatic, ReStatic, u8>>::bar::<ReStatic, char>}`
20-
//[normal]~^^^^ ERROR mismatched types
21-
//[normal]~| expected unit type `()`
22-
//[normal]~| found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::bar::<'static, char>}`
17+
//~^ ERROR mismatched types
18+
//~| expected unit type `()`
19+
//~| found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::bar::<'static, char>}`
2320

2421

2522
let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>;
26-
//[verbose]~^ ERROR mismatched types
27-
//[verbose]~| expected unit type `()`
28-
//[verbose]~| found fn item `fn() {<i8 as Foo<ReStatic, ReStatic>>::bar::<ReStatic, char>}`
29-
//[normal]~^^^^ ERROR mismatched types
30-
//[normal]~| expected unit type `()`
31-
//[normal]~| found fn item `fn() {<i8 as Foo<'static, 'static>>::bar::<'static, char>}`
23+
//~^ ERROR mismatched types
24+
//~| expected unit type `()`
25+
//~| found fn item `fn() {<i8 as Foo<'static, 'static>>::bar::<'static, char>}`
3226

3327
let x: () = <i8 as Foo<'static, 'static, u8>>::baz;
34-
//[verbose]~^ ERROR mismatched types
35-
//[verbose]~| expected unit type `()`
36-
//[verbose]~| found fn item `fn() {<i8 as Foo<ReStatic, ReStatic, u8>>::baz}`
37-
//[normal]~^^^^ ERROR mismatched types
38-
//[normal]~| expected unit type `()`
39-
//[normal]~| found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::baz}`
28+
//~^ ERROR mismatched types
29+
//~| expected unit type `()`
30+
//~| found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::baz}`
4031

4132
let x: () = foo::<'static>;
42-
//[verbose]~^ ERROR mismatched types
43-
//[verbose]~| expected unit type `()`
44-
//[verbose]~| found fn item `fn() {foo::<ReStatic>}`
45-
//[normal]~^^^^ ERROR mismatched types
46-
//[normal]~| expected unit type `()`
47-
//[normal]~| found fn item `fn() {foo::<'static>}`
33+
//~^ ERROR mismatched types
34+
//~| expected unit type `()`
35+
//~| found fn item `fn() {foo::<'static>}`
4836

4937
<str as Foo<u8>>::bar;
50-
//[verbose]~^ ERROR the size for values of type
51-
//[normal]~^^ ERROR the size for values of type
38+
//~^ ERROR the size for values of type
5239
}

src/test/ui/associated-types/substs-ppaux.verbose.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,76 +2,76 @@ error[E0308]: mismatched types
22
--> $DIR/substs-ppaux.rs:16:17
33
|
44
LL | fn bar<'a, T>() where T: 'a {}
5-
| --------------------------- fn() {<i8 as Foo<ReStatic, ReStatic, u8>>::bar::<ReStatic, char>} defined here
5+
| --------------------------- fn() {<i8 as Foo<'static, 'static, u8>>::bar::<'static, char>} defined here
66
...
77
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>;
88
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
99
| |
1010
| expected due to this
1111
|
1212
= note: expected unit type `()`
13-
found fn item `fn() {<i8 as Foo<ReStatic, ReStatic, u8>>::bar::<ReStatic, char>}`
13+
found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::bar::<'static, char>}`
1414
help: use parentheses to call this associated function
1515
|
1616
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>();
1717
| ++
1818

1919
error[E0308]: mismatched types
20-
--> $DIR/substs-ppaux.rs:25:17
20+
--> $DIR/substs-ppaux.rs:22:17
2121
|
2222
LL | fn bar<'a, T>() where T: 'a {}
23-
| --------------------------- fn() {<i8 as Foo<ReStatic, ReStatic>>::bar::<ReStatic, char>} defined here
23+
| --------------------------- fn() {<i8 as Foo<'static, 'static>>::bar::<'static, char>} defined here
2424
...
2525
LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>;
2626
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
2727
| |
2828
| expected due to this
2929
|
3030
= note: expected unit type `()`
31-
found fn item `fn() {<i8 as Foo<ReStatic, ReStatic>>::bar::<ReStatic, char>}`
31+
found fn item `fn() {<i8 as Foo<'static, 'static>>::bar::<'static, char>}`
3232
help: use parentheses to call this associated function
3333
|
3434
LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>();
3535
| ++
3636

3737
error[E0308]: mismatched types
38-
--> $DIR/substs-ppaux.rs:33:17
38+
--> $DIR/substs-ppaux.rs:27:17
3939
|
4040
LL | fn baz() {}
41-
| -------- fn() {<i8 as Foo<ReStatic, ReStatic, u8>>::baz} defined here
41+
| -------- fn() {<i8 as Foo<'static, 'static, u8>>::baz} defined here
4242
...
4343
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz;
4444
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
4545
| |
4646
| expected due to this
4747
|
4848
= note: expected unit type `()`
49-
found fn item `fn() {<i8 as Foo<ReStatic, ReStatic, u8>>::baz}`
49+
found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::baz}`
5050
help: use parentheses to call this associated function
5151
|
5252
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz();
5353
| ++
5454

5555
error[E0308]: mismatched types
56-
--> $DIR/substs-ppaux.rs:41:17
56+
--> $DIR/substs-ppaux.rs:32:17
5757
|
5858
LL | fn foo<'z>() where &'z (): Sized {
59-
| -------------------------------- fn() {foo::<ReStatic>} defined here
59+
| -------------------------------- fn() {foo::<'static>} defined here
6060
...
6161
LL | let x: () = foo::<'static>;
6262
| -- ^^^^^^^^^^^^^^ expected `()`, found fn item
6363
| |
6464
| expected due to this
6565
|
6666
= note: expected unit type `()`
67-
found fn item `fn() {foo::<ReStatic>}`
67+
found fn item `fn() {foo::<'static>}`
6868
help: use parentheses to call this function
6969
|
7070
LL | let x: () = foo::<'static>();
7171
| ++
7272

7373
error[E0277]: the size for values of type `str` cannot be known at compilation time
74-
--> $DIR/substs-ppaux.rs:49:5
74+
--> $DIR/substs-ppaux.rs:37:5
7575
|
7676
LL | <str as Foo<u8>>::bar;
7777
| ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time

src/test/ui/nll/closure-requirements/escape-argument-callee.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | let mut closure = expect_sig(|p, y| *p = y);
66
|
77
= note: defining type: test::{closure#0} with closure substs [
88
i16,
9-
for<'a, 'b, 'c> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) mut &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) i32, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrNamed('c) }) i32)),
9+
for<'a^0, 'b^1, 'c^2> extern "rust-call" fn((&'a^0 mut &'b^1 i32, &'c^2 i32)),
1010
(),
1111
]
1212

src/test/ui/nll/closure-requirements/escape-argument.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | let mut closure = expect_sig(|p, y| *p = y);
66
|
77
= note: defining type: test::{closure#0} with closure substs [
88
i16,
9-
for<'a, 'b> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) mut &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) i32, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) i32)),
9+
for<'a^0, 'b^1> extern "rust-call" fn((&'a^0 mut &'b^1 i32, &'b^1 i32)),
1010
(),
1111
]
1212

0 commit comments

Comments
 (0)