rustc: start moving util::ppaux to ty::print.
This commit is contained in:
parent
228d6f45d8
commit
382d24e7d7
3 changed files with 93 additions and 83 deletions
|
@ -99,6 +99,7 @@ pub mod item_path;
|
|||
pub mod layout;
|
||||
pub mod _match;
|
||||
pub mod outlives;
|
||||
pub mod print;
|
||||
pub mod query;
|
||||
pub mod relate;
|
||||
pub mod steal;
|
||||
|
|
91
src/librustc/ty/print.rs
Normal file
91
src/librustc/ty/print.rs
Normal file
|
@ -0,0 +1,91 @@
|
|||
use crate::ty::{self, TypeFoldable};
|
||||
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use syntax::symbol::InternedString;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
// FIXME(eddyb) this module uses `pub(crate)` for things used only
|
||||
// from `ppaux` - when that is removed, they can be re-privatized.
|
||||
|
||||
struct LateBoundRegionNameCollector(FxHashSet<InternedString>);
|
||||
impl<'tcx> ty::fold::TypeVisitor<'tcx> for LateBoundRegionNameCollector {
|
||||
fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool {
|
||||
match *r {
|
||||
ty::ReLateBound(_, ty::BrNamed(_, name)) => {
|
||||
self.0.insert(name);
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
r.super_visit_with(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PrintContext {
|
||||
pub(crate) is_debug: bool,
|
||||
pub(crate) is_verbose: bool,
|
||||
pub(crate) identify_regions: bool,
|
||||
pub(crate) used_region_names: Option<FxHashSet<InternedString>>,
|
||||
pub(crate) region_index: usize,
|
||||
pub(crate) binder_depth: usize,
|
||||
}
|
||||
|
||||
impl PrintContext {
|
||||
pub(crate) fn new() -> Self {
|
||||
ty::tls::with_opt(|tcx| {
|
||||
let (is_verbose, identify_regions) = tcx.map(
|
||||
|tcx| (tcx.sess.verbose(), tcx.sess.opts.debugging_opts.identify_regions)
|
||||
).unwrap_or((false, false));
|
||||
PrintContext {
|
||||
is_debug: false,
|
||||
is_verbose: is_verbose,
|
||||
identify_regions: identify_regions,
|
||||
used_region_names: None,
|
||||
region_index: 0,
|
||||
binder_depth: 0,
|
||||
}
|
||||
})
|
||||
}
|
||||
pub(crate) fn prepare_late_bound_region_info<'tcx, T>(&mut self, value: &ty::Binder<T>)
|
||||
where T: TypeFoldable<'tcx>
|
||||
{
|
||||
let mut collector = LateBoundRegionNameCollector(Default::default());
|
||||
value.visit_with(&mut collector);
|
||||
self.used_region_names = Some(collector.0);
|
||||
self.region_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Print {
|
||||
fn print<F: fmt::Write>(&self, f: &mut F, cx: &mut PrintContext) -> fmt::Result;
|
||||
fn print_to_string(&self, cx: &mut PrintContext) -> String {
|
||||
let mut result = String::new();
|
||||
let _ = self.print(&mut result, cx);
|
||||
result
|
||||
}
|
||||
fn print_display<F: fmt::Write>(&self, f: &mut F, cx: &mut PrintContext) -> fmt::Result {
|
||||
let old_debug = cx.is_debug;
|
||||
cx.is_debug = false;
|
||||
let result = self.print(f, cx);
|
||||
cx.is_debug = old_debug;
|
||||
result
|
||||
}
|
||||
fn print_display_to_string(&self, cx: &mut PrintContext) -> String {
|
||||
let mut result = String::new();
|
||||
let _ = self.print_display(&mut result, cx);
|
||||
result
|
||||
}
|
||||
fn print_debug<F: fmt::Write>(&self, f: &mut F, cx: &mut PrintContext) -> fmt::Result {
|
||||
let old_debug = cx.is_debug;
|
||||
cx.is_debug = true;
|
||||
let result = self.print(f, cx);
|
||||
cx.is_debug = old_debug;
|
||||
result
|
||||
}
|
||||
fn print_debug_to_string(&self, cx: &mut PrintContext) -> String {
|
||||
let mut result = String::new();
|
||||
let _ = self.print_debug(&mut result, cx);
|
||||
result
|
||||
}
|
||||
}
|
|
@ -9,8 +9,8 @@ use crate::ty::{Param, Bound, RawPtr, Ref, Never, Tuple};
|
|||
use crate::ty::{Closure, Generator, GeneratorWitness, Foreign, Projection, Opaque};
|
||||
use crate::ty::{Placeholder, UnnormalizedProjection, Dynamic, Int, Uint, Infer};
|
||||
use crate::ty::{self, Ty, TyCtxt, TypeFoldable, GenericParamCount, GenericParamDefKind, ParamConst};
|
||||
use crate::ty::print::{PrintContext, Print};
|
||||
use crate::mir::interpret::ConstValue;
|
||||
use crate::util::nodemap::FxHashSet;
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::fmt;
|
||||
|
@ -275,88 +275,6 @@ macro_rules! print {
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
struct LateBoundRegionNameCollector(FxHashSet<InternedString>);
|
||||
impl<'tcx> ty::fold::TypeVisitor<'tcx> for LateBoundRegionNameCollector {
|
||||
fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool {
|
||||
match *r {
|
||||
ty::ReLateBound(_, ty::BrNamed(_, name)) => {
|
||||
self.0.insert(name);
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
r.super_visit_with(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PrintContext {
|
||||
is_debug: bool,
|
||||
is_verbose: bool,
|
||||
identify_regions: bool,
|
||||
used_region_names: Option<FxHashSet<InternedString>>,
|
||||
region_index: usize,
|
||||
binder_depth: usize,
|
||||
}
|
||||
impl PrintContext {
|
||||
fn new() -> Self {
|
||||
ty::tls::with_opt(|tcx| {
|
||||
let (is_verbose, identify_regions) = tcx.map(
|
||||
|tcx| (tcx.sess.verbose(), tcx.sess.opts.debugging_opts.identify_regions)
|
||||
).unwrap_or((false, false));
|
||||
PrintContext {
|
||||
is_debug: false,
|
||||
is_verbose: is_verbose,
|
||||
identify_regions: identify_regions,
|
||||
used_region_names: None,
|
||||
region_index: 0,
|
||||
binder_depth: 0,
|
||||
}
|
||||
})
|
||||
}
|
||||
fn prepare_late_bound_region_info<'tcx, T>(&mut self, value: &ty::Binder<T>)
|
||||
where T: TypeFoldable<'tcx>
|
||||
{
|
||||
let mut collector = LateBoundRegionNameCollector(Default::default());
|
||||
value.visit_with(&mut collector);
|
||||
self.used_region_names = Some(collector.0);
|
||||
self.region_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Print {
|
||||
fn print<F: fmt::Write>(&self, f: &mut F, cx: &mut PrintContext) -> fmt::Result;
|
||||
fn print_to_string(&self, cx: &mut PrintContext) -> String {
|
||||
let mut result = String::new();
|
||||
let _ = self.print(&mut result, cx);
|
||||
result
|
||||
}
|
||||
fn print_display<F: fmt::Write>(&self, f: &mut F, cx: &mut PrintContext) -> fmt::Result {
|
||||
let old_debug = cx.is_debug;
|
||||
cx.is_debug = false;
|
||||
let result = self.print(f, cx);
|
||||
cx.is_debug = old_debug;
|
||||
result
|
||||
}
|
||||
fn print_display_to_string(&self, cx: &mut PrintContext) -> String {
|
||||
let mut result = String::new();
|
||||
let _ = self.print_display(&mut result, cx);
|
||||
result
|
||||
}
|
||||
fn print_debug<F: fmt::Write>(&self, f: &mut F, cx: &mut PrintContext) -> fmt::Result {
|
||||
let old_debug = cx.is_debug;
|
||||
cx.is_debug = true;
|
||||
let result = self.print(f, cx);
|
||||
cx.is_debug = old_debug;
|
||||
result
|
||||
}
|
||||
fn print_debug_to_string(&self, cx: &mut PrintContext) -> String {
|
||||
let mut result = String::new();
|
||||
let _ = self.print_debug(&mut result, cx);
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
impl PrintContext {
|
||||
fn fn_sig<F: fmt::Write>(&mut self,
|
||||
f: &mut F,
|
||||
|
|
Loading…
Reference in a new issue