Skip to content

Commit 795f942

Browse files
committed
rustc: disconnect all the Debug functionality from ty::print.
1 parent 16d6f3d commit 795f942

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
@@ -450,7 +450,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
450450
ty::Adt(..) | ty::Foreign(_) |
451451
ty::Bool | ty::Char | ty::Str |
452452
ty::Int(_) | ty::Uint(_) | ty::Float(_) => {
453-
return self_ty.print_display(self);
453+
return self_ty.print(self);
454454
}
455455

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

463-
p!(print_display(self_ty));
463+
p!(print(self_ty));
464464
if let Some(trait_ref) = trait_ref {
465-
p!(write(" as "), print_display(trait_ref));
465+
p!(write(" as "), print(trait_ref));
466466
}
467467
Ok(cx.printer)
468468
})
@@ -483,9 +483,9 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
483483

484484
p!(write("impl "));
485485
if let Some(trait_ref) = trait_ref {
486-
p!(print_display(trait_ref), write(" for "));
486+
p!(print(trait_ref), write(" for "));
487487
}
488-
p!(print_display(self_ty));
488+
p!(print(self_ty));
489489

490490
Ok(cx.printer)
491491
})
@@ -576,14 +576,14 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
576576
}
577577
}
578578

579-
p!(print_display(arg));
579+
p!(print(arg));
580580
}
581581

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

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

589589
Ok(cx.printer)
@@ -875,7 +875,8 @@ impl<F: fmt::Write> FmtPrinter<F> {
875875
}
876876

877877
if self.tcx.sess.verbose() {
878-
return region.print_debug(self);
878+
p!(write("{:?}", region));
879+
return Ok(self.printer);
879880
}
880881

881882
let identify_regions = self.tcx.sess.opts.debugging_opts.identify_regions;
@@ -963,7 +964,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
963964
ty::Ref(r, ty, mutbl) => {
964965
p!(write("&"));
965966
if self.print_region_outputs_anything(r) {
966-
p!(print_display(r), write(" "));
967+
p!(print(r), write(" "));
967968
}
968969
p!(print(ty::TypeAndMut { ty, mutbl }))
969970
}
@@ -1017,7 +1018,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
10171018
}
10181019
p!(write("dyn "), print(data));
10191020
if print_r {
1020-
p!(write(" + "), print_display(r), write(")"));
1021+
p!(write(" + "), print(r), write(")"));
10211022
}
10221023
}
10231024
ty::Foreign(def_id) => {
@@ -1031,6 +1032,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
10311032
p!(write("Placeholder({:?})", placeholder))
10321033
}
10331034
ty::Opaque(def_id, substs) => {
1035+
// FIXME(eddyb) print this with `print_def_path`.
10341036
if self.tcx.sess.verbose() {
10351037
p!(write("Opaque({:?}, {:?})", def_id, substs));
10361038
return Ok(self.printer);
@@ -1043,9 +1045,9 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
10431045
// FIXME(eddyb) print this with `print_def_path`.
10441046
if let Some(first) = substs.next() {
10451047
p!(write("::<"));
1046-
p!(print_display(first));
1048+
p!(print(first));
10471049
for subst in substs {
1048-
p!(write(", "), print_display(subst));
1050+
p!(write(", "), print(subst));
10491051
}
10501052
p!(write(">"));
10511053
}
@@ -1194,17 +1196,17 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
11941196
p!(write("("));
11951197
let mut inputs = inputs.iter();
11961198
if let Some(&ty) = inputs.next() {
1197-
p!(print_display(ty));
1199+
p!(print(ty));
11981200
for &ty in inputs {
1199-
p!(write(", "), print_display(ty));
1201+
p!(write(", "), print(ty));
12001202
}
12011203
if variadic {
12021204
p!(write(", ..."));
12031205
}
12041206
}
12051207
p!(write(")"));
12061208
if !output.is_unit() {
1207-
p!(write(" -> "), print_display(output));
1209+
p!(write(" -> "), print(output));
12081210
}
12091211

12101212
Ok(self.printer)
@@ -1275,7 +1277,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
12751277
// Push current state to gcx, and restore after writing new_value.
12761278
self.config.binder_depth += 1;
12771279
self.config.region_index = region_index;
1278-
let result = new_value.print_display(PrintCx {
1280+
let result = new_value.print(PrintCx {
12791281
tcx: self.tcx,
12801282
printer: self.printer,
12811283
config: self.config,

0 commit comments

Comments
 (0)