]> git.lizzy.rs Git - rust.git/commitdiff
rustc: start moving util::ppaux to ty::print.
authorEduard-Mihai Burtescu <edy.burt@gmail.com>
Tue, 4 Dec 2018 17:13:37 +0000 (19:13 +0200)
committerEduard-Mihai Burtescu <edy.burt@gmail.com>
Fri, 15 Mar 2019 07:26:13 +0000 (09:26 +0200)
src/librustc/ty/mod.rs
src/librustc/ty/print.rs [new file with mode: 0644]
src/librustc/util/ppaux.rs

index 68bdae7d744c53b3724247d6f6b82852ec73ac96..23fa81f77df282757db3574b105165f15ce91f2a 100644 (file)
@@ -99,6 +99,7 @@
 pub mod layout;
 pub mod _match;
 pub mod outlives;
+pub mod print;
 pub mod query;
 pub mod relate;
 pub mod steal;
diff --git a/src/librustc/ty/print.rs b/src/librustc/ty/print.rs
new file mode 100644 (file)
index 0000000..f58bb28
--- /dev/null
@@ -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
+    }
+}
index a1398c69ff0c59ea69732cbe4f5c269c948f914e..24b9779654a2049a926db00e4599b80b466185ac 100644 (file)
@@ -9,8 +9,8 @@
 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,