Skip to content

Commit dda6ae8

Browse files
committed
rustc: move ty::print::PrintConfig's fields to FmtPrinter.
1 parent 55b4193 commit dda6ae8

File tree

8 files changed

+195
-196
lines changed

8 files changed

+195
-196
lines changed

src/librustc/infer/error_reporting/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
527527
// module we could have false positives
528528
if !(did1.is_local() || did2.is_local()) && did1.krate != did2.krate {
529529
let abs_path = |def_id| {
530-
PrintCx::with(self.tcx, AbsolutePathPrinter, |cx| {
531-
cx.print_def_path(def_id, None, iter::empty())
532-
})
530+
PrintCx::new(self.tcx, AbsolutePathPrinter)
531+
.print_def_path(def_id, None, iter::empty())
533532
};
534533

535534
// We compare strings because DefPath can be different

src/librustc/infer/error_reporting/need_type_info.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
8484
if let Some(highlight) = highlight {
8585
printer.region_highlight_mode = highlight;
8686
}
87-
let _ = ty::print::PrintCx::with(self.tcx, printer, |cx| {
88-
ty.print(cx)
89-
});
87+
let _ = ty.print(ty::print::PrintCx::new(self.tcx, printer));
9088
s
9189
}
9290

src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,14 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
250250
printer.region_highlight_mode.maybe_highlighting_region(sub_placeholder, has_sub);
251251
printer.region_highlight_mode.maybe_highlighting_region(sup_placeholder, has_sup);
252252

253-
let _ = ty::print::PrintCx::with(self.tcx, printer, |mut cx| {
254-
write!(cx.printer, "`")?;
253+
let _ = (|| {
254+
let mut cx = ty::print::PrintCx::new(self.tcx, printer);
255+
write!(cx, "`")?;
255256
cx = cx.nest(|cx| expected_trait_ref.self_ty().print(cx))?;
256-
write!(cx.printer, "` must implement `")?;
257+
write!(cx, "` must implement `")?;
257258
cx = cx.nest(|cx| expected_trait_ref.print(cx))?;
258-
write!(cx.printer, "`")
259-
});
259+
write!(cx, "`")
260+
})();
260261

261262
match (has_sub, has_sup) {
262263
(Some(n1), Some(n2)) => {
@@ -283,13 +284,14 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
283284
let mut printer = ty::print::FmtPrinter::new(&mut note, Namespace::TypeNS);
284285
printer.region_highlight_mode.maybe_highlighting_region(vid, has_vid);
285286

286-
let _ = ty::print::PrintCx::with(self.tcx, printer, |mut cx| {
287-
write!(cx.printer, "but `")?;
287+
let _ = (|| {
288+
let mut cx = ty::print::PrintCx::new(self.tcx, printer);
289+
write!(cx, "but `")?;
288290
cx = cx.nest(|cx| actual_trait_ref.self_ty().print(cx))?;
289-
write!(cx.printer, "` only implements `")?;
291+
write!(cx, "` only implements `")?;
290292
cx = cx.nest(|cx| actual_trait_ref.print(cx))?;
291-
write!(cx.printer, "`")
292-
});
293+
write!(cx, "`")
294+
})();
293295

294296
if let Some(n) = has_vid {
295297
let _ = write!(note,

src/librustc/ty/print/mod.rs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,50 @@ use ty::{self, DefIdTree, Ty, TyCtxt};
44
use ty::subst::{Subst, Substs};
55

66
use rustc_data_structures::fx::FxHashSet;
7-
use syntax::symbol::InternedString;
87

98
use std::iter;
10-
use std::ops::Deref;
9+
use std::ops::{Deref, DerefMut};
1110

1211
// `pretty` is a separate module only for organization.
1312
mod pretty;
1413
pub use self::pretty::*;
1514

16-
#[derive(Default)]
17-
struct PrintConfig {
18-
used_region_names: Option<FxHashSet<InternedString>>,
19-
region_index: usize,
20-
binder_depth: usize,
21-
}
22-
2315
pub struct PrintCx<'a, 'gcx, 'tcx, P> {
2416
pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
25-
pub printer: P,
26-
config: &'a mut PrintConfig,
17+
inner: P,
2718
}
2819

29-
// HACK(eddyb) this is solely for `self: PrintCx<Self>`, e.g. to
30-
// implement traits on the printer and call the methods on the context.
3120
impl<P> Deref for PrintCx<'_, '_, '_, P> {
3221
type Target = P;
3322
fn deref(&self) -> &P {
34-
&self.printer
23+
&self.inner
24+
}
25+
}
26+
27+
impl<P> DerefMut for PrintCx<'_, '_, '_, P> {
28+
fn deref_mut(&mut self) -> &mut P {
29+
&mut self.inner
3530
}
3631
}
3732

3833
impl<'a, 'gcx, 'tcx, P> PrintCx<'a, 'gcx, 'tcx, P> {
39-
pub fn with<R>(
40-
tcx: TyCtxt<'a, 'gcx, 'tcx>,
41-
printer: P,
42-
f: impl FnOnce(PrintCx<'_, 'gcx, 'tcx, P>) -> R,
43-
) -> R {
44-
f(PrintCx {
34+
pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>, inner: P) -> Self {
35+
PrintCx {
4536
tcx,
46-
printer,
47-
config: &mut PrintConfig::default(),
48-
})
37+
inner,
38+
}
39+
}
40+
41+
pub fn with_tls_tcx<R>(inner: P, f: impl FnOnce(PrintCx<'_, '_, '_, P>) -> R) -> R {
42+
ty::tls::with(|tcx| f(PrintCx::new(tcx, inner)))
43+
}
44+
45+
pub fn into_inner(self) -> P {
46+
self.inner
4947
}
5048

51-
pub fn with_tls_tcx<R>(printer: P, f: impl FnOnce(PrintCx<'_, '_, '_, P>) -> R) -> R {
52-
ty::tls::with(|tcx| PrintCx::with(tcx, printer, f))
49+
pub fn ok<E>(self) -> Result<P, E> {
50+
Ok(self.into_inner())
5351
}
5452
}
5553

0 commit comments

Comments
 (0)