Skip to content

Commit 4d0a89f

Browse files
committed
rustc: remove fields from ty::print::PrintConfig available from tcx.
1 parent 297cb8e commit 4d0a89f

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
@@ -2341,20 +2341,20 @@ impl<'tcx> Debug for Rvalue<'tcx> {
23412341
};
23422342

23432343
// When printing regions, add trailing space if necessary.
2344-
let ns = Namespace::ValueNS;
2345-
ty::print::PrintCx::with_tls_tcx(ty::print::FmtPrinter::new(fmt, ns), |mut cx| {
2346-
let region = if cx.config.is_verbose || cx.config.identify_regions {
2347-
let mut region = region.to_string();
2348-
if region.len() > 0 {
2349-
region.push(' ');
2350-
}
2351-
region
2352-
} else {
2353-
// Do not even print 'static
2354-
String::new()
2355-
};
2356-
write!(cx.printer, "&{}{}{:?}", region, kind_str, place)
2357-
})
2344+
let print_region = ty::tls::with(|tcx| {
2345+
tcx.sess.verbose() || tcx.sess.opts.debugging_opts.identify_regions
2346+
});
2347+
let region = if print_region {
2348+
let mut region = region.to_string();
2349+
if region.len() > 0 {
2350+
region.push(' ');
2351+
}
2352+
region
2353+
} else {
2354+
// Do not even print 'static
2355+
String::new()
2356+
};
2357+
write!(fmt, "&{}{}{:?}", region, kind_str, place)
23582358
}
23592359

23602360
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
@@ -514,7 +514,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
514514
});
515515

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

819-
if self.config.is_verbose {
819+
if self.tcx.sess.verbose() {
820820
return true;
821821
}
822822

823+
let identify_regions = self.tcx.sess.opts.debugging_opts.identify_regions;
824+
823825
match *region {
824826
ty::ReEarlyBound(ref data) => {
825827
data.name != "" && data.name != "'_"
@@ -844,7 +846,7 @@ impl<F: fmt::Write> PrettyPrinter for FmtPrinter<F> {
844846
}
845847

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

849851
ty::ReVar(_) |
850852
ty::ReScope(_) |
@@ -872,10 +874,12 @@ impl<F: fmt::Write> FmtPrinter<F> {
872874
return Ok(self.printer);
873875
}
874876

875-
if self.config.is_verbose {
877+
if self.tcx.sess.verbose() {
876878
return region.print_debug(self);
877879
}
878880

881+
let identify_regions = self.tcx.sess.opts.debugging_opts.identify_regions;
882+
879883
// These printouts are concise. They do not contain all the information
880884
// the user might want to diagnose an error, but there is basically no way
881885
// to fit that into a short string. Hence the recommendation to use
@@ -902,7 +906,7 @@ impl<F: fmt::Write> FmtPrinter<F> {
902906
}
903907
}
904908
}
905-
ty::ReScope(scope) if self.config.identify_regions => {
909+
ty::ReScope(scope) if identify_regions => {
906910
match scope.data {
907911
region::ScopeData::Node =>
908912
p!(write("'{}s", scope.item_local_id().as_usize())),
@@ -919,7 +923,7 @@ impl<F: fmt::Write> FmtPrinter<F> {
919923
)),
920924
}
921925
}
922-
ty::ReVar(region_vid) if self.config.identify_regions => {
926+
ty::ReVar(region_vid) if identify_regions => {
923927
p!(write("{:?}", region_vid));
924928
}
925929
ty::ReVar(_) => {}
@@ -1027,7 +1031,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
10271031
p!(write("Placeholder({:?})", placeholder))
10281032
}
10291033
ty::Opaque(def_id, substs) => {
1030-
if self.config.is_verbose {
1034+
if self.tcx.sess.verbose() {
10311035
p!(write("Opaque({:?}, {:?})", def_id, substs));
10321036
return Ok(self.printer);
10331037
}

src/librustc/util/ppaux.rs

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

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

0 commit comments

Comments
 (0)