Skip to content

Commit

Permalink
update region debug formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
BoxyUwU committed Mar 18, 2024
1 parent 13abc0a commit cb8cc43
Show file tree
Hide file tree
Showing 30 changed files with 189 additions and 155 deletions.
18 changes: 16 additions & 2 deletions compiler/rustc_middle/src/ty/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,9 @@ pub struct EarlyParamRegion {

impl std::fmt::Debug for EarlyParamRegion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}, {}, {}", self.def_id, self.index, self.name)
// self.def_id goes first because of `erased-regions-in-hidden-ty.rs` being impossible to write
// error annotations for otherwise. :)
write!(f, "({:?})_{}/#{}", self.def_id, self.name, self.index)
}
}

Expand Down Expand Up @@ -381,13 +383,25 @@ pub enum BoundRegionKind {
BrEnv,
}

#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, PartialOrd, Ord)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, PartialOrd, Ord)]
#[derive(HashStable)]
pub struct BoundRegion {
pub var: BoundVar,
pub kind: BoundRegionKind,
}

impl core::fmt::Debug for BoundRegion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.kind {
BoundRegionKind::BrAnon => write!(f, "{:?}", self.var),
BoundRegionKind::BrEnv => write!(f, "{:?}_Env", self.var),
BoundRegionKind::BrNamed(def, symbol) => {
write!(f, "{:?}_Named({:?}, {:?})", self.var, def, symbol)
}
}
}
}

impl BoundRegionKind {
pub fn is_named(&self) -> bool {
match *self {
Expand Down
13 changes: 7 additions & 6 deletions compiler/rustc_type_ir/src/region_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,23 +223,24 @@ impl<I: Interner> DebugWithInfcx<I> for RegionKind<I> {
f: &mut core::fmt::Formatter<'_>,
) -> core::fmt::Result {
match this.data {
ReEarlyParam(data) => write!(f, "ReEarlyParam({data:?})"),
ReEarlyParam(data) => write!(f, "{data:?}"),

ReBound(binder_id, bound_region) => {
write!(f, "ReBound({binder_id:?}, {bound_region:?})")
write!(f, "'")?;
crate::debug_bound_var(f, *binder_id, bound_region)
}

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

ReStatic => f.write_str("ReStatic"),
ReStatic => f.write_str("'static"),

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

RePlaceholder(placeholder) => write!(f, "RePlaceholder({placeholder:?})"),
RePlaceholder(placeholder) => write!(f, "{placeholder:?}"),

ReErased => f.write_str("ReErased"),
ReErased => f.write_str("'erased"),

ReError(_) => f.write_str("ReError"),
ReError(_) => f.write_str("{{region error}}"),
}
}
}
Expand Down
78 changes: 42 additions & 36 deletions tests/ui/associated-types/substs-ppaux.normal.stderr
Original file line number Diff line number Diff line change
@@ -1,67 +1,73 @@
error[E0308]: mismatched types
--> $DIR/substs-ppaux.rs:16:17
--> $DIR/substs-ppaux.rs:23:17
|
LL | fn bar<'a, T>() where T: 'a {}
| --------------------------- associated function `bar` defined here
LL | / fn bar<'a, T>()
LL | | where
LL | | T: 'a,
| |______________- associated function `bar` defined here
...
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>;
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
| |
| expected due to this
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>;
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
| |
| expected due to this
|
= note: expected unit type `()`
found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::bar::<'static, char>}`
help: use parentheses to call this associated function
|
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>();
| ++
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>();
| ++

error[E0308]: mismatched types
--> $DIR/substs-ppaux.rs:25:17
--> $DIR/substs-ppaux.rs:31:17
|
LL | fn bar<'a, T>() where T: 'a {}
| --------------------------- associated function `bar` defined here
LL | / fn bar<'a, T>()
LL | | where
LL | | T: 'a,
| |______________- associated function `bar` defined here
...
LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>;
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
| |
| expected due to this
LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>;
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
| |
| expected due to this
|
= note: expected unit type `()`
found fn item `fn() {<i8 as Foo<'static, 'static>>::bar::<'static, char>}`
help: use parentheses to call this associated function
|
LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>();
| ++
LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>();
| ++

error[E0308]: mismatched types
--> $DIR/substs-ppaux.rs:33:17
--> $DIR/substs-ppaux.rs:39:17
|
LL | fn baz() {}
| -------- associated function `baz` defined here
...
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz;
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz;
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
| |
| expected due to this
|
= note: expected unit type `()`
found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::baz}`
help: use parentheses to call this associated function
|
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz();
| ++
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz();
| ++

error[E0308]: mismatched types
--> $DIR/substs-ppaux.rs:41:17
--> $DIR/substs-ppaux.rs:47:17
|
LL | fn foo<'z>() where &'z (): Sized {
| -------------------------------- function `foo` defined here
LL | / fn foo<'z>()
LL | | where
LL | | &'z (): Sized,
| |__________________- function `foo` defined here
...
LL | let x: () = foo::<'static>;
| -- ^^^^^^^^^^^^^^ expected `()`, found fn item
| |
| expected due to this
LL | let x: () = foo::<'static>;
| -- ^^^^^^^^^^^^^^ expected `()`, found fn item
| |
| expected due to this
|
= note: expected unit type `()`
found fn item `fn() {foo::<'static>}`
Expand All @@ -71,18 +77,18 @@ LL | let x: () = foo::<'static>();
| ++

error[E0277]: the trait bound `str: Foo<'_, '_, u8>` is not satisfied
--> $DIR/substs-ppaux.rs:49:6
--> $DIR/substs-ppaux.rs:55:6
|
LL | <str as Foo<u8>>::bar;
| ^^^ the trait `Sized` is not implemented for `str`, which is required by `str: Foo<'_, '_, u8>`
|
note: required for `str` to implement `Foo<'_, '_, u8>`
--> $DIR/substs-ppaux.rs:11:17
--> $DIR/substs-ppaux.rs:15:20
|
LL | impl<'a,'b,T,S> Foo<'a, 'b, S> for T {}
| - ^^^^^^^^^^^^^^ ^
| |
| unsatisfied trait bound introduced here
LL | impl<'a, 'b, T, S> Foo<'a, 'b, S> for T {}
| - ^^^^^^^^^^^^^^ ^
| |
| unsatisfied trait bound introduced here

error: aborting due to 5 previous errors

Expand Down
30 changes: 18 additions & 12 deletions tests/ui/associated-types/substs-ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,51 @@
//
//@[verbose] compile-flags: -Z verbose-internals

trait Foo<'b, 'c, S=u32> {
fn bar<'a, T>() where T: 'a {}
trait Foo<'b, 'c, S = u32> {
fn bar<'a, T>()
where
T: 'a,
{
}
fn baz() {}
}

impl<'a,'b,T,S> Foo<'a, 'b, S> for T {}
impl<'a, 'b, T, S> Foo<'a, 'b, S> for T {}

fn main() {}

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


let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>;
let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>;
//[verbose]~^ ERROR mismatched types
//[verbose]~| expected unit type `()`
//[verbose]~| found fn item `fn() {<i8 as Foo<ReStatic, ReStatic>>::bar::<ReStatic, char>}`
//[verbose]~| found fn item `fn() {<i8 as Foo<'static, 'static>>::bar::<'static, char>}`
//[normal]~^^^^ ERROR mismatched types
//[normal]~| expected unit type `()`
//[normal]~| found fn item `fn() {<i8 as Foo<'static, 'static>>::bar::<'static, char>}`

let x: () = <i8 as Foo<'static, 'static, u8>>::baz;
let x: () = <i8 as Foo<'static, 'static, u8>>::baz;
//[verbose]~^ ERROR mismatched types
//[verbose]~| expected unit type `()`
//[verbose]~| found fn item `fn() {<i8 as Foo<ReStatic, ReStatic, u8>>::baz}`
//[verbose]~| found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::baz}`
//[normal]~^^^^ ERROR mismatched types
//[normal]~| expected unit type `()`
//[normal]~| found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::baz}`

let x: () = foo::<'static>;
//[verbose]~^ ERROR mismatched types
//[verbose]~| expected unit type `()`
//[verbose]~| found fn item `fn() {foo::<ReStatic>}`
//[verbose]~| found fn item `fn() {foo::<'static>}`
//[normal]~^^^^ ERROR mismatched types
//[normal]~| expected unit type `()`
//[normal]~| found fn item `fn() {foo::<'static>}`
Expand Down
86 changes: 46 additions & 40 deletions tests/ui/associated-types/substs-ppaux.verbose.stderr
Original file line number Diff line number Diff line change
@@ -1,88 +1,94 @@
error[E0308]: mismatched types
--> $DIR/substs-ppaux.rs:16:17
--> $DIR/substs-ppaux.rs:23:17
|
LL | fn bar<'a, T>() where T: 'a {}
| --------------------------- associated function `bar` defined here
LL | / fn bar<'a, T>()
LL | | where
LL | | T: 'a,
| |______________- associated function `bar` defined here
...
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>;
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
| |
| expected due to this
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>;
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
| |
| expected due to this
|
= note: expected unit type `()`
found fn item `fn() {<i8 as Foo<ReStatic, ReStatic, u8>>::bar::<ReStatic, char>}`
found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::bar::<'static, char>}`
help: use parentheses to call this associated function
|
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>();
| ++
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>();
| ++

error[E0308]: mismatched types
--> $DIR/substs-ppaux.rs:25:17
--> $DIR/substs-ppaux.rs:31:17
|
LL | fn bar<'a, T>() where T: 'a {}
| --------------------------- associated function `bar` defined here
LL | / fn bar<'a, T>()
LL | | where
LL | | T: 'a,
| |______________- associated function `bar` defined here
...
LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>;
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
| |
| expected due to this
LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>;
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
| |
| expected due to this
|
= note: expected unit type `()`
found fn item `fn() {<i8 as Foo<ReStatic, ReStatic>>::bar::<ReStatic, char>}`
found fn item `fn() {<i8 as Foo<'static, 'static>>::bar::<'static, char>}`
help: use parentheses to call this associated function
|
LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>();
| ++
LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>();
| ++

error[E0308]: mismatched types
--> $DIR/substs-ppaux.rs:33:17
--> $DIR/substs-ppaux.rs:39:17
|
LL | fn baz() {}
| -------- associated function `baz` defined here
...
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz;
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz;
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
| |
| expected due to this
|
= note: expected unit type `()`
found fn item `fn() {<i8 as Foo<ReStatic, ReStatic, u8>>::baz}`
found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::baz}`
help: use parentheses to call this associated function
|
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz();
| ++
LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz();
| ++

error[E0308]: mismatched types
--> $DIR/substs-ppaux.rs:41:17
--> $DIR/substs-ppaux.rs:47:17
|
LL | fn foo<'z>() where &'z (): Sized {
| -------------------------------- function `foo` defined here
LL | / fn foo<'z>()
LL | | where
LL | | &'z (): Sized,
| |__________________- function `foo` defined here
...
LL | let x: () = foo::<'static>;
| -- ^^^^^^^^^^^^^^ expected `()`, found fn item
| |
| expected due to this
LL | let x: () = foo::<'static>;
| -- ^^^^^^^^^^^^^^ expected `()`, found fn item
| |
| expected due to this
|
= note: expected unit type `()`
found fn item `fn() {foo::<ReStatic>}`
found fn item `fn() {foo::<'static>}`
help: use parentheses to call this function
|
LL | let x: () = foo::<'static>();
| ++

error[E0277]: the trait bound `str: Foo<'?0, '?1, u8>` is not satisfied
--> $DIR/substs-ppaux.rs:49:6
--> $DIR/substs-ppaux.rs:55:6
|
LL | <str as Foo<u8>>::bar;
| ^^^ the trait `Sized` is not implemented for `str`, which is required by `str: Foo<'?0, '?1, u8>`
|
note: required for `str` to implement `Foo<'?0, '?1, u8>`
--> $DIR/substs-ppaux.rs:11:17
--> $DIR/substs-ppaux.rs:15:20
|
LL | impl<'a,'b,T,S> Foo<'a, 'b, S> for T {}
| - ^^^^^^^^^^^^^^ ^
| |
| unsatisfied trait bound introduced here
LL | impl<'a, 'b, T, S> Foo<'a, 'b, S> for T {}
| - ^^^^^^^^^^^^^^ ^
| |
| unsatisfied trait bound introduced here

error: aborting due to 5 previous errors

Expand Down
Loading

0 comments on commit cb8cc43

Please sign in to comment.