Skip to content

Commit 381fa7a

Browse files
committed
rustc: move ty::print::PrintConfig's fields to FmtPrinter.
1 parent 1a0f3a2 commit 381fa7a

File tree

8 files changed

+185
-190
lines changed

8 files changed

+185
-190
lines changed

src/librustc/infer/error_reporting/mod.rs

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

534533
// 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: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,8 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
347347
let mut printer = ty::print::FmtPrinter::new(f, Namespace::TypeNS);
348348
printer.region_highlight_mode = self.highlight;
349349

350-
ty::print::PrintCx::with(self.tcx, printer, |cx| {
351-
self.value.print(cx)?;
352-
Ok(())
353-
})
350+
self.value.print(ty::print::PrintCx::new(self.tcx, printer))?;
351+
Ok(())
354352
}
355353
}
356354

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 crate::ty::{self, DefIdTree, Ty, TyCtxt};
44
use crate::ty::subst::{Subst, SubstsRef};
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)