From 800ddb367e4a56a77ab940ce95023e82b64f3bd2 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Fri, 18 Jan 2019 21:45:13 +0200 Subject: [PATCH] rustc: remove fields from ty::print::PrintConfig available from tcx. --- src/librustc/mir/mod.rs | 28 ++++++++++++++-------------- src/librustc/ty/print/mod.rs | 18 ++---------------- src/librustc/ty/print/pretty.rs | 18 +++++++++++------- src/librustc/util/ppaux.rs | 4 ++-- 4 files changed, 29 insertions(+), 39 deletions(-) diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 0165bba5ed7..c0f0df004c6 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -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) => { diff --git a/src/librustc/ty/print/mod.rs b/src/librustc/ty/print/mod.rs index 9d93d1a34a1..ccd2a702c9f 100644 --- a/src/librustc/ty/print/mod.rs +++ b/src/librustc/ty/print/mod.rs @@ -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>, 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(), }) } diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index caa4090625d..325897dc042 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -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 PrettyPrinter for FmtPrinter { 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 PrettyPrinter for FmtPrinter { } 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 FmtPrinter { 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 FmtPrinter { } } } - 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 FmtPrinter { )), } } - 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); } diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 059a3614704..20df306dd2a 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -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 {