Skip to content

Commit 800ddb3

Browse files
committed
rustc: remove fields from ty::print::PrintConfig available from tcx.
1 parent 55871aa commit 800ddb3

File tree

4 files changed

+29
-39
lines changed

4 files changed

+29
-39
lines changed

src/librustc/mir/mod.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,20 +2369,20 @@ impl<'tcx> Debug for Rvalue<'tcx> {
23692369
};
23702370

23712371
// When printing regions, add trailing space if necessary.
2372-
let ns = Namespace::ValueNS;
2373-
ty::print::PrintCx::with_tls_tcx(ty::print::FmtPrinter::new(fmt, ns), |mut cx| {
2374-
let region = if cx.config.is_verbose || cx.config.identify_regions {
2375-
let mut region = region.to_string();
2376-
if region.len() > 0 {
2377-
region.push(' ');
2378-
}
2379-
region
2380-
} else {
2381-
// Do not even print 'static
2382-
String::new()
2383-
};
2384-
write!(cx.printer, "&{}{}{:?}", region, kind_str, place)
2385-
})
2372+
let print_region = ty::tls::with(|tcx| {
2373+
tcx.sess.verbose() || tcx.sess.opts.debugging_opts.identify_regions
2374+
});
2375+
let region = if print_region {
2376+
let mut region = region.to_string();
2377+
if region.len() > 0 {
2378+
region.push(' ');
2379+
}
2380+
region
2381+
} else {
2382+
// Do not even print 'static
2383+
String::new()
2384+
};
2385+
write!(fmt, "&{}{}{:?}", region, kind_str, place)
23862386
}
23872387

23882388
Aggregate(ref kind, ref places) => {

src/librustc/ty/print/mod.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,14 @@ impl<'tcx> ty::fold::TypeVisitor<'tcx> for LateBoundRegionNameCollector {
2929
}
3030
}
3131

32+
#[derive(Default)]
3233
pub(crate) struct PrintConfig {
3334
pub(crate) is_debug: bool,
34-
pub(crate) is_verbose: bool,
35-
pub(crate) identify_regions: bool,
3635
used_region_names: Option<FxHashSet<InternedString>>,
3736
region_index: usize,
3837
binder_depth: usize,
3938
}
4039

41-
impl PrintConfig {
42-
fn new(tcx: TyCtxt<'_, '_, '_>) -> Self {
43-
PrintConfig {
44-
is_debug: false,
45-
is_verbose: tcx.sess.verbose(),
46-
identify_regions: tcx.sess.opts.debugging_opts.identify_regions,
47-
used_region_names: None,
48-
region_index: 0,
49-
binder_depth: 0,
50-
}
51-
}
52-
}
53-
5440
pub struct PrintCx<'a, 'gcx, 'tcx, P> {
5541
pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
5642
pub printer: P,
@@ -75,7 +61,7 @@ impl<'a, 'gcx, 'tcx, P> PrintCx<'a, 'gcx, 'tcx, P> {
7561
f(PrintCx {
7662
tcx,
7763
printer,
78-
config: &mut PrintConfig::new(tcx),
64+
config: &mut PrintConfig::default(),
7965
})
8066
}
8167

src/librustc/ty/print/pretty.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
515515
});
516516

517517
// Don't print args that are the defaults of their respective parameters.
518-
let num_supplied_defaults = if self.config.is_verbose {
518+
let num_supplied_defaults = if self.tcx.sess.verbose() {
519519
0
520520
} else {
521521
params.iter().rev().take_while(|param| {
@@ -818,10 +818,12 @@ impl<F: fmt::Write> PrettyPrinter for FmtPrinter<F> {
818818
return true;
819819
}
820820

821-
if self.config.is_verbose {
821+
if self.tcx.sess.verbose() {
822822
return true;
823823
}
824824

825+
let identify_regions = self.tcx.sess.opts.debugging_opts.identify_regions;
826+
825827
match *region {
826828
ty::ReEarlyBound(ref data) => {
827829
data.name != "" && data.name != "'_"
@@ -846,7 +848,7 @@ impl<F: fmt::Write> PrettyPrinter for FmtPrinter<F> {
846848
}
847849

848850
ty::ReScope(_) |
849-
ty::ReVar(_) if self.config.identify_regions => true,
851+
ty::ReVar(_) if identify_regions => true,
850852

851853
ty::ReVar(_) |
852854
ty::ReScope(_) |
@@ -874,10 +876,12 @@ impl<F: fmt::Write> FmtPrinter<F> {
874876
return Ok(self.printer);
875877
}
876878

877-
if self.config.is_verbose {
879+
if self.tcx.sess.verbose() {
878880
return region.print_debug(self);
879881
}
880882

883+
let identify_regions = self.tcx.sess.opts.debugging_opts.identify_regions;
884+
881885
// These printouts are concise. They do not contain all the information
882886
// the user might want to diagnose an error, but there is basically no way
883887
// to fit that into a short string. Hence the recommendation to use
@@ -904,7 +908,7 @@ impl<F: fmt::Write> FmtPrinter<F> {
904908
}
905909
}
906910
}
907-
ty::ReScope(scope) if self.config.identify_regions => {
911+
ty::ReScope(scope) if identify_regions => {
908912
match scope.data {
909913
region::ScopeData::Node =>
910914
p!(write("'{}s", scope.item_local_id().as_usize())),
@@ -921,7 +925,7 @@ impl<F: fmt::Write> FmtPrinter<F> {
921925
)),
922926
}
923927
}
924-
ty::ReVar(region_vid) if self.config.identify_regions => {
928+
ty::ReVar(region_vid) if identify_regions => {
925929
p!(write("{:?}", region_vid));
926930
}
927931
ty::ReVar(_) => {}
@@ -1029,7 +1033,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
10291033
p!(write("Placeholder({:?})", placeholder))
10301034
}
10311035
ty::Opaque(def_id, substs) => {
1032-
if self.config.is_verbose {
1036+
if self.tcx.sess.verbose() {
10331037
p!(write("Opaque({:?}, {:?})", def_id, substs));
10341038
return Ok(self.printer);
10351039
}

src/librustc/util/ppaux.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ define_print! {
166166

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

0 commit comments

Comments
 (0)