Skip to content

Commit 9c42485

Browse files
committed
rustc: disconnect all the Debug functionality from ty::print.
1 parent d0a1bf5 commit 9c42485

File tree

3 files changed

+141
-210
lines changed

3 files changed

+141
-210
lines changed

src/librustc/ty/print/mod.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ impl<'tcx> ty::fold::TypeVisitor<'tcx> for LateBoundRegionNameCollector {
3131

3232
#[derive(Default)]
3333
pub(crate) struct PrintConfig {
34-
pub(crate) is_debug: bool,
3534
used_region_names: Option<FxHashSet<InternedString>>,
3635
region_index: usize,
3736
binder_depth: usize,
@@ -83,31 +82,6 @@ pub trait Print<'tcx, P> {
8382
type Error;
8483

8584
fn print(&self, cx: PrintCx<'_, '_, 'tcx, P>) -> Result<Self::Output, Self::Error>;
86-
fn print_display(
87-
&self,
88-
cx: PrintCx<'_, '_, 'tcx, P>,
89-
) -> Result<Self::Output, Self::Error> {
90-
let old_debug = cx.config.is_debug;
91-
cx.config.is_debug = false;
92-
let result = self.print(PrintCx {
93-
tcx: cx.tcx,
94-
printer: cx.printer,
95-
config: cx.config,
96-
});
97-
cx.config.is_debug = old_debug;
98-
result
99-
}
100-
fn print_debug(&self, cx: PrintCx<'_, '_, 'tcx, P>) -> Result<Self::Output, Self::Error> {
101-
let old_debug = cx.config.is_debug;
102-
cx.config.is_debug = true;
103-
let result = self.print(PrintCx {
104-
tcx: cx.tcx,
105-
printer: cx.printer,
106-
config: cx.config,
107-
});
108-
cx.config.is_debug = old_debug;
109-
result
110-
}
11185
}
11286

11387
pub trait Printer: Sized {

src/librustc/ty/print/pretty.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
451451
ty::Adt(..) | ty::Foreign(_) |
452452
ty::Bool | ty::Char | ty::Str |
453453
ty::Int(_) | ty::Uint(_) | ty::Float(_) => {
454-
return self_ty.print_display(self);
454+
return self_ty.print(self);
455455
}
456456

457457
_ => {}
@@ -461,9 +461,9 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
461461
self.generic_delimiters(|mut cx| {
462462
define_scoped_cx!(cx);
463463

464-
p!(print_display(self_ty));
464+
p!(print(self_ty));
465465
if let Some(trait_ref) = trait_ref {
466-
p!(write(" as "), print_display(trait_ref));
466+
p!(write(" as "), print(trait_ref));
467467
}
468468
Ok(cx.printer)
469469
})
@@ -484,9 +484,9 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
484484

485485
p!(write("impl "));
486486
if let Some(trait_ref) = trait_ref {
487-
p!(print_display(trait_ref), write(" for "));
487+
p!(print(trait_ref), write(" for "));
488488
}
489-
p!(print_display(self_ty));
489+
p!(print(self_ty));
490490

491491
Ok(cx.printer)
492492
})
@@ -578,14 +578,14 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
578578
}
579579
}
580580

581-
p!(print_display(arg));
581+
p!(print(arg));
582582
}
583583

584584
for projection in projection0.into_iter().chain(projections) {
585585
maybe_comma(&mut cx)?;
586586

587587
p!(write("{}=", cx.tcx.associated_item(projection.item_def_id).ident),
588-
print_display(projection.ty));
588+
print(projection.ty));
589589
}
590590

591591
Ok(cx.printer)
@@ -877,7 +877,8 @@ impl<F: fmt::Write> FmtPrinter<F> {
877877
}
878878

879879
if self.tcx.sess.verbose() {
880-
return region.print_debug(self);
880+
p!(write("{:?}", region));
881+
return Ok(self.printer);
881882
}
882883

883884
let identify_regions = self.tcx.sess.opts.debugging_opts.identify_regions;
@@ -965,7 +966,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
965966
ty::Ref(r, ty, mutbl) => {
966967
p!(write("&"));
967968
if self.print_region_outputs_anything(r) {
968-
p!(print_display(r), write(" "));
969+
p!(print(r), write(" "));
969970
}
970971
p!(print(ty::TypeAndMut { ty, mutbl }))
971972
}
@@ -1019,7 +1020,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
10191020
}
10201021
p!(write("dyn "), print(data));
10211022
if print_r {
1022-
p!(write(" + "), print_display(r), write(")"));
1023+
p!(write(" + "), print(r), write(")"));
10231024
}
10241025
}
10251026
ty::Foreign(def_id) => {
@@ -1033,6 +1034,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
10331034
p!(write("Placeholder({:?})", placeholder))
10341035
}
10351036
ty::Opaque(def_id, substs) => {
1037+
// FIXME(eddyb) print this with `print_def_path`.
10361038
if self.tcx.sess.verbose() {
10371039
p!(write("Opaque({:?}, {:?})", def_id, substs));
10381040
return Ok(self.printer);
@@ -1045,9 +1047,9 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
10451047
// FIXME(eddyb) print this with `print_def_path`.
10461048
if let Some(first) = substs.next() {
10471049
p!(write("::<"));
1048-
p!(print_display(first));
1050+
p!(print(first));
10491051
for subst in substs {
1050-
p!(write(", "), print_display(subst));
1052+
p!(write(", "), print(subst));
10511053
}
10521054
p!(write(">"));
10531055
}
@@ -1209,17 +1211,17 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
12091211
p!(write("("));
12101212
let mut inputs = inputs.iter();
12111213
if let Some(&ty) = inputs.next() {
1212-
p!(print_display(ty));
1214+
p!(print(ty));
12131215
for &ty in inputs {
1214-
p!(write(", "), print_display(ty));
1216+
p!(write(", "), print(ty));
12151217
}
12161218
if c_variadic {
12171219
p!(write(", ..."));
12181220
}
12191221
}
12201222
p!(write(")"));
12211223
if !output.is_unit() {
1222-
p!(write(" -> "), print_display(output));
1224+
p!(write(" -> "), print(output));
12231225
}
12241226

12251227
Ok(self.printer)
@@ -1290,7 +1292,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
12901292
// Push current state to gcx, and restore after writing new_value.
12911293
self.config.binder_depth += 1;
12921294
self.config.region_index = region_index;
1293-
let result = new_value.print_display(PrintCx {
1295+
let result = new_value.print(PrintCx {
12941296
tcx: self.tcx,
12951297
printer: self.printer,
12961298
config: self.config,

0 commit comments

Comments
 (0)