rustc: remove fields from ty::print::PrintConfig available from tcx.

This commit is contained in:
Eduard-Mihai Burtescu 2019-01-18 21:45:13 +02:00
parent 55871aad9a
commit 800ddb367e
4 changed files with 29 additions and 39 deletions

View file

@ -2369,20 +2369,20 @@ impl<'tcx> Debug for Rvalue<'tcx> {
};
// When printing regions, add trailing space if necessary.
let ns = Namespace::ValueNS;
ty::print::PrintCx::with_tls_tcx(ty::print::FmtPrinter::new(fmt, ns), |mut cx| {
let region = if cx.config.is_verbose || cx.config.identify_regions {
let mut region = region.to_string();
if region.len() > 0 {
region.push(' ');
}
region
} else {
// Do not even print 'static
String::new()
};
write!(cx.printer, "&{}{}{:?}", region, kind_str, place)
})
let print_region = ty::tls::with(|tcx| {
tcx.sess.verbose() || tcx.sess.opts.debugging_opts.identify_regions
});
let region = if print_region {
let mut region = region.to_string();
if region.len() > 0 {
region.push(' ');
}
region
} else {
// Do not even print 'static
String::new()
};
write!(fmt, "&{}{}{:?}", region, kind_str, place)
}
Aggregate(ref kind, ref places) => {

View file

@ -29,28 +29,14 @@ impl<'tcx> ty::fold::TypeVisitor<'tcx> for LateBoundRegionNameCollector {
}
}
#[derive(Default)]
pub(crate) struct PrintConfig {
pub(crate) is_debug: bool,
pub(crate) is_verbose: bool,
pub(crate) identify_regions: bool,
used_region_names: Option<FxHashSet<InternedString>>,
region_index: usize,
binder_depth: usize,
}
impl PrintConfig {
fn new(tcx: TyCtxt<'_, '_, '_>) -> Self {
PrintConfig {
is_debug: false,
is_verbose: tcx.sess.verbose(),
identify_regions: tcx.sess.opts.debugging_opts.identify_regions,
used_region_names: None,
region_index: 0,
binder_depth: 0,
}
}
}
pub struct PrintCx<'a, 'gcx, 'tcx, P> {
pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
pub printer: P,
@ -75,7 +61,7 @@ impl<'a, 'gcx, 'tcx, P> PrintCx<'a, 'gcx, 'tcx, P> {
f(PrintCx {
tcx,
printer,
config: &mut PrintConfig::new(tcx),
config: &mut PrintConfig::default(),
})
}

View file

@ -515,7 +515,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
});
// Don't print args that are the defaults of their respective parameters.
let num_supplied_defaults = if self.config.is_verbose {
let num_supplied_defaults = if self.tcx.sess.verbose() {
0
} else {
params.iter().rev().take_while(|param| {
@ -818,10 +818,12 @@ impl<F: fmt::Write> PrettyPrinter for FmtPrinter<F> {
return true;
}
if self.config.is_verbose {
if self.tcx.sess.verbose() {
return true;
}
let identify_regions = self.tcx.sess.opts.debugging_opts.identify_regions;
match *region {
ty::ReEarlyBound(ref data) => {
data.name != "" && data.name != "'_"
@ -846,7 +848,7 @@ impl<F: fmt::Write> PrettyPrinter for FmtPrinter<F> {
}
ty::ReScope(_) |
ty::ReVar(_) if self.config.identify_regions => true,
ty::ReVar(_) if identify_regions => true,
ty::ReVar(_) |
ty::ReScope(_) |
@ -874,10 +876,12 @@ impl<F: fmt::Write> FmtPrinter<F> {
return Ok(self.printer);
}
if self.config.is_verbose {
if self.tcx.sess.verbose() {
return region.print_debug(self);
}
let identify_regions = self.tcx.sess.opts.debugging_opts.identify_regions;
// These printouts are concise. They do not contain all the information
// the user might want to diagnose an error, but there is basically no way
// to fit that into a short string. Hence the recommendation to use
@ -904,7 +908,7 @@ impl<F: fmt::Write> FmtPrinter<F> {
}
}
}
ty::ReScope(scope) if self.config.identify_regions => {
ty::ReScope(scope) if identify_regions => {
match scope.data {
region::ScopeData::Node =>
p!(write("'{}s", scope.item_local_id().as_usize())),
@ -921,7 +925,7 @@ impl<F: fmt::Write> FmtPrinter<F> {
)),
}
}
ty::ReVar(region_vid) if self.config.identify_regions => {
ty::ReVar(region_vid) if identify_regions => {
p!(write("{:?}", region_vid));
}
ty::ReVar(_) => {}
@ -1029,7 +1033,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
p!(write("Placeholder({:?})", placeholder))
}
ty::Opaque(def_id, substs) => {
if self.config.is_verbose {
if self.tcx.sess.verbose() {
p!(write("Opaque({:?}, {:?})", def_id, substs));
return Ok(self.printer);
}

View file

@ -166,7 +166,7 @@ define_print! {
// Special-case `Fn(...) -> ...` and resugar it.
let fn_trait_kind = cx.tcx.lang_items().fn_trait_kind(principal.def_id);
if !cx.config.is_verbose && fn_trait_kind.is_some() {
if !cx.tcx.sess.verbose() && fn_trait_kind.is_some() {
if let ty::Tuple(ref args) = principal.substs.type_at(0).sty {
let mut projections = self.projection_bounds();
if let (Some(proj), None) = (projections.next(), projections.next()) {
@ -463,7 +463,7 @@ impl fmt::Debug for ty::RegionVid {
define_print! {
() ty::InferTy, (self, cx) {
display {
if cx.config.is_verbose {
if cx.tcx.sess.verbose() {
return self.print_debug(cx);
}
match *self {