Skip to content

Commit 4e1af5e

Browse files
committed
rustc: remove fields from ty::print::PrintConfig available from tcx.
1 parent 9ff30f1 commit 4e1af5e

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
@@ -518,7 +518,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
518518
});
519519

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

823-
if self.config.is_verbose {
823+
if self.tcx.sess.verbose() {
824824
return true;
825825
}
826826

827+
let identify_regions = self.tcx.sess.opts.debugging_opts.identify_regions;
828+
827829
match *region {
828830
ty::ReEarlyBound(ref data) => {
829831
data.name != "" && data.name != "'_"
@@ -848,7 +850,7 @@ impl<F: fmt::Write> PrettyPrinter for FmtPrinter<F> {
848850
}
849851

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

853855
ty::ReVar(_) |
854856
ty::ReScope(_) |
@@ -876,10 +878,12 @@ impl<F: fmt::Write> FmtPrinter<F> {
876878
return Ok(self.printer);
877879
}
878880

879-
if self.config.is_verbose {
881+
if self.tcx.sess.verbose() {
880882
return region.print_debug(self);
881883
}
882884

885+
let identify_regions = self.tcx.sess.opts.debugging_opts.identify_regions;
886+
883887
// These printouts are concise. They do not contain all the information
884888
// the user might want to diagnose an error, but there is basically no way
885889
// to fit that into a short string. Hence the recommendation to use
@@ -906,7 +910,7 @@ impl<F: fmt::Write> FmtPrinter<F> {
906910
}
907911
}
908912
}
909-
ty::ReScope(scope) if self.config.identify_regions => {
913+
ty::ReScope(scope) if identify_regions => {
910914
match scope.data {
911915
region::ScopeData::Node =>
912916
p!(write("'{}s", scope.item_local_id().as_usize())),
@@ -923,7 +927,7 @@ impl<F: fmt::Write> FmtPrinter<F> {
923927
)),
924928
}
925929
}
926-
ty::ReVar(region_vid) if self.config.identify_regions => {
930+
ty::ReVar(region_vid) if identify_regions => {
927931
p!(write("{:?}", region_vid));
928932
}
929933
ty::ReVar(_) => {}
@@ -1031,7 +1035,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
10311035
p!(write("Placeholder({:?})", placeholder))
10321036
}
10331037
ty::Opaque(def_id, substs) => {
1034-
if self.config.is_verbose {
1038+
if self.tcx.sess.verbose() {
10351039
p!(write("Opaque({:?}, {:?})", def_id, substs));
10361040
return Ok(self.printer);
10371041
}

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)