Skip to content

Commit 239df7b

Browse files
committed
Bypass ppaux for Outlives predicates
1 parent 3510805 commit 239df7b

File tree

8 files changed

+48
-18
lines changed

8 files changed

+48
-18
lines changed

src/librustc/traits/structural_impls.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,41 @@ impl<'tcx> fmt::Display for traits::WhereClause<'tcx> {
442442
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
443443
use traits::WhereClause::*;
444444

445+
// Bypass ppaux because it does not print out anonymous regions.
446+
fn write_region_name<'tcx>(
447+
r: ty::Region<'tcx>,
448+
fmt: &mut fmt::Formatter<'_>
449+
) -> fmt::Result {
450+
match r {
451+
ty::ReLateBound(index, br) => match br {
452+
ty::BoundRegion::BrNamed(_, name) => write!(fmt, "{}", name),
453+
ty::BoundRegion::BrAnon(var) => {
454+
if *index == ty::INNERMOST {
455+
write!(fmt, "'^{}", var)
456+
} else {
457+
write!(fmt, "'^{}_{}", index.index(), var)
458+
}
459+
}
460+
_ => write!(fmt, "'_"),
461+
}
462+
463+
_ => write!(fmt, "{}", r),
464+
}
465+
}
466+
445467
match self {
446468
Implemented(trait_ref) => write!(fmt, "Implemented({})", trait_ref),
447469
ProjectionEq(projection) => write!(fmt, "ProjectionEq({})", projection),
448-
RegionOutlives(predicate) => write!(fmt, "RegionOutlives({})", predicate),
449-
TypeOutlives(predicate) => write!(fmt, "TypeOutlives({})", predicate),
470+
RegionOutlives(predicate) => {
471+
write!(fmt, "RegionOutlives({}: ", predicate.0)?;
472+
write_region_name(predicate.1, fmt)?;
473+
write!(fmt, ")")
474+
}
475+
TypeOutlives(predicate) => {
476+
write!(fmt, "TypeOutlives({}: ", predicate.0)?;
477+
write_region_name(predicate.1, fmt)?;
478+
write!(fmt, ")")
479+
}
450480
}
451481
}
452482
}
@@ -567,7 +597,7 @@ impl<'tcx> TypeVisitor<'tcx> for BoundNamesCollector {
567597
match bound_ty.kind {
568598
ty::BoundTyKind::Param(name) => name,
569599
ty::BoundTyKind::Anon => Symbol::intern(
570-
&format!("?{}", bound_ty.var.as_u32())
600+
&format!("^{}", bound_ty.var.as_u32())
571601
).as_interned_str(),
572602
}
573603
);
@@ -591,7 +621,7 @@ impl<'tcx> TypeVisitor<'tcx> for BoundNamesCollector {
591621

592622
ty::BoundRegion::BrAnon(var) => {
593623
self.regions.insert(Symbol::intern(
594-
&format!("?'{}", var)
624+
&format!("'^{}", var)
595625
).as_interned_str());
596626
}
597627

src/librustc/util/ppaux.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,9 +1114,9 @@ define_print! {
11141114
match bound_ty.kind {
11151115
ty::BoundTyKind::Anon => {
11161116
if bound_ty.index == ty::INNERMOST {
1117-
write!(f, "?{}", bound_ty.var.index())
1117+
write!(f, "^{}", bound_ty.var.index())
11181118
} else {
1119-
write!(f, "?{}_{}", bound_ty.index.index(), bound_ty.var.index())
1119+
write!(f, "^{}_{}", bound_ty.index.index(), bound_ty.var.index())
11201120
}
11211121
}
11221122

src/librustc_traits/chalk_context/program_clauses.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ fn program_clauses_for_tuple<'tcx>(
191191
.map(|i| ty::BoundTy::new(ty::INNERMOST, ty::BoundVar::from(i)))
192192
.map(|t| tcx.mk_ty(ty::Bound(t)))
193193
);
194-
194+
195195
let tuple_ty = tcx.mk_ty(ty::Tuple(type_list));
196196

197197
let sized_trait = match tcx.lang_items().sized_trait() {

src/test/ui/chalkify/lower_env2.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: forall<'a, T> { FromEnv(T: Foo) :- FromEnv(S<'a, T>). }
8-
= note: forall<'a, T> { TypeOutlives(T : 'a) :- FromEnv(S<'a, T>). }
9-
= note: forall<'a, T> { WellFormed(S<'a, T>) :- Implemented(T: Foo), TypeOutlives(T : 'a). }
8+
= note: forall<'a, T> { TypeOutlives(T: 'a) :- FromEnv(S<'a, T>). }
9+
= note: forall<'a, T> { WellFormed(S<'a, T>) :- Implemented(T: Foo), TypeOutlives(T: 'a). }
1010

1111
error: program clause dump
1212
--> $DIR/lower_env2.rs:21:1
@@ -15,7 +15,7 @@ LL | #[rustc_dump_env_program_clauses] //~ ERROR program clause dump
1515
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1616
|
1717
= note: forall<'a, T> { FromEnv(T: Foo) :- FromEnv(S<'a, T>). }
18-
= note: forall<'a, T> { TypeOutlives(T : 'a) :- FromEnv(S<'a, T>). }
18+
= note: forall<'a, T> { TypeOutlives(T: 'a) :- FromEnv(S<'a, T>). }
1919
= note: forall<Self> { Implemented(Self: Foo) :- FromEnv(Self: Foo). }
2020
= note: forall<Self> { Implemented(Self: std::marker::Sized) :- FromEnv(Self: std::marker::Sized). }
2121

src/test/ui/chalkify/lower_env3.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: program clause dump
44
LL | #[rustc_dump_env_program_clauses] //~ ERROR program clause dump
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: forall<?'0, ?1> { TypeOutlives(?1 : ) :- FromEnv(&?1). }
7+
= note: forall<'^0, ^1> { TypeOutlives(^1: '^0) :- FromEnv(&^1). }
88
= note: forall<Self> { Implemented(Self: Foo) :- FromEnv(Self: Foo). }
99

1010
error: program clause dump
@@ -13,7 +13,7 @@ error: program clause dump
1313
LL | #[rustc_dump_env_program_clauses] //~ ERROR program clause dump
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515
|
16-
= note: forall<?'0, ?1> { TypeOutlives(?1 : ) :- FromEnv(&?1). }
16+
= note: forall<'^0, ^1> { TypeOutlives(^1: '^0) :- FromEnv(&^1). }
1717
= note: forall<Self> { FromEnv(Self: std::marker::Sized) :- FromEnv(Self: std::clone::Clone). }
1818
= note: forall<Self> { Implemented(Self: std::clone::Clone) :- FromEnv(Self: std::clone::Clone). }
1919
= note: forall<Self> { Implemented(Self: std::marker::Sized) :- FromEnv(Self: std::marker::Sized). }

src/test/ui/chalkify/lower_impl.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: program clause dump
44
LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: forall<T> { Implemented(T: Foo) :- ProjectionEq(<T as std::iter::Iterator>::Item == i32), TypeOutlives(T : 'static), Implemented(T: std::iter::Iterator), Implemented(T: std::marker::Sized). }
7+
= note: forall<T> { Implemented(T: Foo) :- ProjectionEq(<T as std::iter::Iterator>::Item == i32), TypeOutlives(T: 'static), Implemented(T: std::iter::Iterator), Implemented(T: std::marker::Sized). }
88

99
error: program clause dump
1010
--> $DIR/lower_impl.rs:23:5

src/test/ui/chalkify/lower_struct.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
66
|
77
= note: forall<'a, T> { FromEnv(T: std::marker::Sized) :- FromEnv(Foo<'a, T>). }
88
= note: forall<'a, T> { FromEnv(std::boxed::Box<T>: std::clone::Clone) :- FromEnv(Foo<'a, T>). }
9-
= note: forall<'a, T> { TypeOutlives(T : 'a) :- FromEnv(Foo<'a, T>). }
10-
= note: forall<'a, T> { WellFormed(Foo<'a, T>) :- Implemented(T: std::marker::Sized), Implemented(std::boxed::Box<T>: std::clone::Clone), TypeOutlives(T : 'a). }
9+
= note: forall<'a, T> { TypeOutlives(T: 'a) :- FromEnv(Foo<'a, T>). }
10+
= note: forall<'a, T> { WellFormed(Foo<'a, T>) :- Implemented(T: std::marker::Sized), Implemented(std::boxed::Box<T>: std::clone::Clone), TypeOutlives(T: 'a). }
1111

1212
error: aborting due to previous error
1313

src/test/ui/chalkify/lower_trait_where_clause.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
66
|
77
= note: forall<'a, 'b, Self, T, U> { FromEnv(T: std::borrow::Borrow<U>) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
88
= note: forall<'a, 'b, Self, T, U> { Implemented(Self: Foo<'a, 'b, T, U>) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
9-
= note: forall<'a, 'b, Self, T, U> { RegionOutlives('a : 'b) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
10-
= note: forall<'a, 'b, Self, T, U> { TypeOutlives(U : 'b) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
11-
= note: forall<'a, 'b, Self, T, U> { WellFormed(Self: Foo<'a, 'b, T, U>) :- Implemented(Self: Foo<'a, 'b, T, U>), WellFormed(T: std::borrow::Borrow<U>), TypeOutlives(U : 'b), RegionOutlives('a : 'b), WellFormed(std::boxed::Box<T>). }
9+
= note: forall<'a, 'b, Self, T, U> { RegionOutlives('a: 'b) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
10+
= note: forall<'a, 'b, Self, T, U> { TypeOutlives(U: 'b) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
11+
= note: forall<'a, 'b, Self, T, U> { WellFormed(Self: Foo<'a, 'b, T, U>) :- Implemented(Self: Foo<'a, 'b, T, U>), WellFormed(T: std::borrow::Borrow<U>), TypeOutlives(U: 'b), RegionOutlives('a: 'b), WellFormed(std::boxed::Box<T>). }
1212
= note: forall<'a, 'b, Self, T, U> { WellFormed(std::boxed::Box<T>) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
1313

1414
error: aborting due to previous error

0 commit comments

Comments
 (0)