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
+14 -14
View File
@@ -2369,20 +2369,20 @@ fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
};
// 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) => {
+2 -16
View File
@@ -29,28 +29,14 @@ fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool {
}
}
#[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 @@ pub fn with<R>(
f(PrintCx {
tcx,
printer,
config: &mut PrintConfig::new(tcx),
config: &mut PrintConfig::default(),
})
}
+11 -7
View File
@@ -515,7 +515,7 @@ pub fn pretty_path_generic_args(
});
// 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 @@ fn print_region_outputs_anything(
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 @@ fn print_region_outputs_anything(
}
ty::ReScope(_) |
ty::ReVar(_) if self.config.identify_regions => true,
ty::ReVar(_) if identify_regions => true,
ty::ReVar(_) |
ty::ReScope(_) |
@@ -874,10 +876,12 @@ pub fn pretty_print_region(
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 @@ pub fn pretty_print_region(
}
}
}
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 @@ pub fn pretty_print_region(
)),
}
}
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 @@ pub fn pretty_print_type(
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);
}
+2 -2
View File
@@ -166,7 +166,7 @@ pub fn parameterized<F: fmt::Write>(
// 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 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
define_print! {
() ty::InferTy, (self, cx) {
display {
if cx.config.is_verbose {
if cx.tcx.sess.verbose() {
return self.print_debug(cx);
}
match *self {