Skip to content

Commit 206b0f2

Browse files
committed
rustc: disconnect all the Debug functionality from ty::print.
1 parent 2b789be commit 206b0f2

File tree

3 files changed

+136
-205
lines changed

3 files changed

+136
-205
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
@@ -454,7 +454,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
454454
ty::Adt(..) | ty::Foreign(_) |
455455
ty::Bool | ty::Char | ty::Str |
456456
ty::Int(_) | ty::Uint(_) | ty::Float(_) => {
457-
return self_ty.print_display(self);
457+
return self_ty.print(self);
458458
}
459459

460460
_ => {}
@@ -464,9 +464,9 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
464464
self.generic_delimiters(|mut cx| {
465465
define_scoped_cx!(cx);
466466

467-
p!(print_display(self_ty));
467+
p!(print(self_ty));
468468
if let Some(trait_ref) = trait_ref {
469-
p!(write(" as "), print_display(trait_ref));
469+
p!(write(" as "), print(trait_ref));
470470
}
471471
Ok(cx.printer)
472472
})
@@ -487,9 +487,9 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
487487

488488
p!(write("impl "));
489489
if let Some(trait_ref) = trait_ref {
490-
p!(print_display(trait_ref), write(" for "));
490+
p!(print(trait_ref), write(" for "));
491491
}
492-
p!(print_display(self_ty));
492+
p!(print(self_ty));
493493

494494
Ok(cx.printer)
495495
})
@@ -580,14 +580,14 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
580580
}
581581
}
582582

583-
p!(print_display(arg));
583+
p!(print(arg));
584584
}
585585

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

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

593593
Ok(cx.printer)
@@ -879,7 +879,8 @@ impl<F: fmt::Write> FmtPrinter<F> {
879879
}
880880

881881
if self.tcx.sess.verbose() {
882-
return region.print_debug(self);
882+
p!(write("{:?}", region));
883+
return Ok(self.printer);
883884
}
884885

885886
let identify_regions = self.tcx.sess.opts.debugging_opts.identify_regions;
@@ -967,7 +968,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
967968
ty::Ref(r, ty, mutbl) => {
968969
p!(write("&"));
969970
if self.print_region_outputs_anything(r) {
970-
p!(print_display(r), write(" "));
971+
p!(print(r), write(" "));
971972
}
972973
p!(print(ty::TypeAndMut { ty, mutbl }))
973974
}
@@ -1021,7 +1022,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
10211022
}
10221023
p!(write("dyn "), print(data));
10231024
if print_r {
1024-
p!(write(" + "), print_display(r), write(")"));
1025+
p!(write(" + "), print(r), write(")"));
10251026
}
10261027
}
10271028
ty::Foreign(def_id) => {
@@ -1035,6 +1036,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
10351036
p!(write("Placeholder({:?})", placeholder))
10361037
}
10371038
ty::Opaque(def_id, substs) => {
1039+
// FIXME(eddyb) print this with `print_def_path`.
10381040
if self.tcx.sess.verbose() {
10391041
p!(write("Opaque({:?}, {:?})", def_id, substs));
10401042
return Ok(self.printer);
@@ -1047,9 +1049,9 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
10471049
// FIXME(eddyb) print this with `print_def_path`.
10481050
if let Some(first) = substs.next() {
10491051
p!(write("::<"));
1050-
p!(print_display(first));
1052+
p!(print(first));
10511053
for subst in substs {
1052-
p!(write(", "), print_display(subst));
1054+
p!(write(", "), print(subst));
10531055
}
10541056
p!(write(">"));
10551057
}
@@ -1198,17 +1200,17 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
11981200
p!(write("("));
11991201
let mut inputs = inputs.iter();
12001202
if let Some(&ty) = inputs.next() {
1201-
p!(print_display(ty));
1203+
p!(print(ty));
12021204
for &ty in inputs {
1203-
p!(write(", "), print_display(ty));
1205+
p!(write(", "), print(ty));
12041206
}
12051207
if variadic {
12061208
p!(write(", ..."));
12071209
}
12081210
}
12091211
p!(write(")"));
12101212
if !output.is_unit() {
1211-
p!(write(" -> "), print_display(output));
1213+
p!(write(" -> "), print(output));
12121214
}
12131215

12141216
Ok(self.printer)
@@ -1279,7 +1281,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
12791281
// Push current state to gcx, and restore after writing new_value.
12801282
self.config.binder_depth += 1;
12811283
self.config.region_index = region_index;
1282-
let result = new_value.print_display(PrintCx {
1284+
let result = new_value.print(PrintCx {
12831285
tcx: self.tcx,
12841286
printer: self.printer,
12851287
config: self.config,

0 commit comments

Comments
 (0)