Skip to content
Permalink
Browse files

rustc: move ty::print::PrintConfig's fields to FmtPrinter.

  • Loading branch information...
eddyb committed Jan 20, 2019
1 parent 1a0f3a2 commit 381fa7aa18d0440d122c476bdbd074281a93b6a9
@@ -526,9 +526,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
// module we could have false positives
if !(did1.is_local() || did2.is_local()) && did1.krate != did2.krate {
let abs_path = |def_id| {
PrintCx::with(self.tcx, AbsolutePathPrinter, |cx| {
cx.print_def_path(def_id, None, iter::empty())
})
PrintCx::new(self.tcx, AbsolutePathPrinter)
.print_def_path(def_id, None, iter::empty())
};

// We compare strings because DefPath can be different
@@ -84,9 +84,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
if let Some(highlight) = highlight {
printer.region_highlight_mode = highlight;
}
let _ = ty::print::PrintCx::with(self.tcx, printer, |cx| {
ty.print(cx)
});
let _ = ty.print(ty::print::PrintCx::new(self.tcx, printer));
s
}

@@ -347,10 +347,8 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
let mut printer = ty::print::FmtPrinter::new(f, Namespace::TypeNS);
printer.region_highlight_mode = self.highlight;

ty::print::PrintCx::with(self.tcx, printer, |cx| {
self.value.print(cx)?;
Ok(())
})
self.value.print(ty::print::PrintCx::new(self.tcx, printer))?;
Ok(())
}
}

@@ -4,52 +4,50 @@ use crate::ty::{self, DefIdTree, Ty, TyCtxt};
use crate::ty::subst::{Subst, SubstsRef};

use rustc_data_structures::fx::FxHashSet;
use syntax::symbol::InternedString;

use std::iter;
use std::ops::Deref;
use std::ops::{Deref, DerefMut};

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

#[derive(Default)]
struct PrintConfig {
used_region_names: Option<FxHashSet<InternedString>>,
region_index: usize,
binder_depth: usize,
}

pub struct PrintCx<'a, 'gcx, 'tcx, P> {
pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
pub printer: P,
config: &'a mut PrintConfig,
inner: P,
}

// HACK(eddyb) this is solely for `self: PrintCx<Self>`, e.g. to
// implement traits on the printer and call the methods on the context.
impl<P> Deref for PrintCx<'_, '_, '_, P> {
type Target = P;
fn deref(&self) -> &P {
&self.printer
&self.inner
}
}

impl<P> DerefMut for PrintCx<'_, '_, '_, P> {
fn deref_mut(&mut self) -> &mut P {
&mut self.inner
}
}

impl<'a, 'gcx, 'tcx, P> PrintCx<'a, 'gcx, 'tcx, P> {
pub fn with<R>(
tcx: TyCtxt<'a, 'gcx, 'tcx>,
printer: P,
f: impl FnOnce(PrintCx<'_, 'gcx, 'tcx, P>) -> R,
) -> R {
f(PrintCx {
pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>, inner: P) -> Self {
PrintCx {
tcx,
printer,
config: &mut PrintConfig::default(),
})
inner,
}
}

pub fn with_tls_tcx<R>(inner: P, f: impl FnOnce(PrintCx<'_, '_, '_, P>) -> R) -> R {
ty::tls::with(|tcx| f(PrintCx::new(tcx, inner)))
}

pub fn into_inner(self) -> P {
self.inner
}

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

Oops, something went wrong.

0 comments on commit 381fa7a

Please sign in to comment.
You can’t perform that action at this time.