Skip to content

Commit 4831932

Browse files
committed
rustc: keep a TyCtxt in PrintCx and use it instead of ty::tls.
1 parent 93fd485 commit 4831932

File tree

3 files changed

+188
-206
lines changed

3 files changed

+188
-206
lines changed

src/librustc/mir/mod.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,17 +2341,19 @@ impl<'tcx> Debug for Rvalue<'tcx> {
23412341
};
23422342

23432343
// When printing regions, add trailing space if necessary.
2344-
let region = if ppaux::verbose() || ppaux::identify_regions() {
2345-
let mut region = region.to_string();
2346-
if region.len() > 0 {
2347-
region.push(' ');
2348-
}
2349-
region
2350-
} else {
2351-
// Do not even print 'static
2352-
String::new()
2353-
};
2354-
write!(fmt, "&{}{}{:?}", region, kind_str, place)
2344+
ty::print::PrintCx::with(|cx| {
2345+
let region = if cx.is_verbose || cx.identify_regions {
2346+
let mut region = region.to_string();
2347+
if region.len() > 0 {
2348+
region.push(' ');
2349+
}
2350+
region
2351+
} else {
2352+
// Do not even print 'static
2353+
String::new()
2354+
};
2355+
write!(fmt, "&{}{}{:?}", region, kind_str, place)
2356+
})
23552357
}
23562358

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

src/librustc/ty/print.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use ty::{self, TypeFoldable};
1+
use ty::{self, TyCtxt, TypeFoldable};
22

33
use rustc_data_structures::fx::FxHashSet;
44
use syntax::symbol::InternedString;
@@ -21,8 +21,8 @@ impl<'tcx> ty::fold::TypeVisitor<'tcx> for LateBoundRegionNameCollector {
2121
}
2222
}
2323

24-
#[derive(Debug)]
25-
pub struct PrintCx {
24+
pub struct PrintCx<'a, 'gcx, 'tcx> {
25+
pub(crate) tcx: TyCtxt<'a, 'gcx, 'tcx>,
2626
pub(crate) is_debug: bool,
2727
pub(crate) is_verbose: bool,
2828
pub(crate) identify_regions: bool,
@@ -31,22 +31,21 @@ pub struct PrintCx {
3131
pub(crate) binder_depth: usize,
3232
}
3333

34-
impl PrintCx {
35-
pub(crate) fn new() -> Self {
34+
impl PrintCx<'a, 'gcx, 'tcx> {
35+
pub(crate) fn with<R>(f: impl FnOnce(PrintCx<'_, '_, '_>) -> R) -> R {
3636
ty::tls::with(|tcx| {
37-
let (is_verbose, identify_regions) =
38-
(tcx.sess.verbose(), tcx.sess.opts.debugging_opts.identify_regions);
39-
PrintCx {
37+
f(PrintCx {
38+
tcx,
4039
is_debug: false,
41-
is_verbose: is_verbose,
42-
identify_regions: identify_regions,
40+
is_verbose: tcx.sess.verbose(),
41+
identify_regions: tcx.sess.opts.debugging_opts.identify_regions,
4342
used_region_names: None,
4443
region_index: 0,
4544
binder_depth: 0,
46-
}
45+
})
4746
})
4847
}
49-
pub(crate) fn prepare_late_bound_region_info<'tcx, T>(&mut self, value: &ty::Binder<T>)
48+
pub(crate) fn prepare_late_bound_region_info<T>(&mut self, value: &ty::Binder<T>)
5049
where T: TypeFoldable<'tcx>
5150
{
5251
let mut collector = LateBoundRegionNameCollector(Default::default());
@@ -57,32 +56,32 @@ impl PrintCx {
5756
}
5857

5958
pub trait Print<'tcx> {
60-
fn print<F: fmt::Write>(&self, f: &mut F, cx: &mut PrintCx) -> fmt::Result;
61-
fn print_to_string(&self, cx: &mut PrintCx) -> String {
59+
fn print<F: fmt::Write>(&self, f: &mut F, cx: &mut PrintCx<'_, '_, '_>) -> fmt::Result;
60+
fn print_to_string(&self, cx: &mut PrintCx<'_, '_, '_>) -> String {
6261
let mut result = String::new();
6362
let _ = self.print(&mut result, cx);
6463
result
6564
}
66-
fn print_display<F: fmt::Write>(&self, f: &mut F, cx: &mut PrintCx) -> fmt::Result {
65+
fn print_display<F: fmt::Write>(&self, f: &mut F, cx: &mut PrintCx<'_, '_, '_>) -> fmt::Result {
6766
let old_debug = cx.is_debug;
6867
cx.is_debug = false;
6968
let result = self.print(f, cx);
7069
cx.is_debug = old_debug;
7170
result
7271
}
73-
fn print_display_to_string(&self, cx: &mut PrintCx) -> String {
72+
fn print_display_to_string(&self, cx: &mut PrintCx<'_, '_, '_>) -> String {
7473
let mut result = String::new();
7574
let _ = self.print_display(&mut result, cx);
7675
result
7776
}
78-
fn print_debug<F: fmt::Write>(&self, f: &mut F, cx: &mut PrintCx) -> fmt::Result {
77+
fn print_debug<F: fmt::Write>(&self, f: &mut F, cx: &mut PrintCx<'_, '_, '_>) -> fmt::Result {
7978
let old_debug = cx.is_debug;
8079
cx.is_debug = true;
8180
let result = self.print(f, cx);
8281
cx.is_debug = old_debug;
8382
result
8483
}
85-
fn print_debug_to_string(&self, cx: &mut PrintCx) -> String {
84+
fn print_debug_to_string(&self, cx: &mut PrintCx<'_, '_, '_>) -> String {
8685
let mut result = String::new();
8786
let _ = self.print_debug(&mut result, cx);
8887
result

0 commit comments

Comments
 (0)