about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEduard-Mihai Burtescu <edy.burt@gmail.com>2018-12-12 18:28:29 +0200
committerEduard-Mihai Burtescu <edy.burt@gmail.com>2019-03-15 09:26:14 +0200
commited2be6fa89428b6c0a43e41a8906d29bc78f62d0 (patch)
tree5b5a62e14acb8e00afb33ab27eb6c48b7bcf1d01
parent238616813974babc53cb85aaa8e102df119d7f0f (diff)
downloadrust-ed2be6fa89428b6c0a43e41a8906d29bc78f62d0.tar.gz
rust-ed2be6fa89428b6c0a43e41a8906d29bc78f62d0.zip
rustc: move the FORCE_IMPL_FILENAME_LINE handling into LocalPathPrinter.
-rw-r--r--src/librustc/ty/item_path.rs52
1 files changed, 26 insertions, 26 deletions
diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs
index 0612401ca25..87859ac00c3 100644
--- a/src/librustc/ty/item_path.rs
+++ b/src/librustc/ty/item_path.rs
@@ -91,7 +91,7 @@ impl<P: ItemPathPrinter> PrintCx<'a, 'gcx, 'tcx, P> {
             }
 
             DefPathData::Impl => {
-                self.default_print_impl_path(def_id)
+                self.print_impl_path(def_id)
             }
 
             // Unclear if there is any value in distinguishing these.
@@ -132,18 +132,6 @@ impl<P: ItemPathPrinter> PrintCx<'a, 'gcx, 'tcx, P> {
         debug!("default_print_impl_path: impl_def_id={:?}", impl_def_id);
         let parent_def_id = self.tcx.parent_def_id(impl_def_id).unwrap();
 
-        // Always use types for non-local impls, where types are always
-        // available, and filename/line-number is mostly uninteresting.
-        let use_types = !impl_def_id.is_local() || {
-            // Otherwise, use filename/line-number if forced.
-            let force_no_types = FORCE_IMPL_FILENAME_LINE.with(|f| f.get());
-            !force_no_types
-        };
-
-        if !use_types {
-            return self.default_print_impl_path_fallback(impl_def_id);
-        }
-
         // Decide whether to print the parent path for the impl.
         // Logically, since impls are global, it's never needed, but
         // users may find it useful. Currently, we omit the parent if
@@ -210,19 +198,6 @@ impl<P: ItemPathPrinter> PrintCx<'a, 'gcx, 'tcx, P> {
             }
         }
     }
-
-    fn default_print_impl_path_fallback(&mut self, impl_def_id: DefId) -> P::Path {
-        // If no type info is available, fall back to
-        // pretty printing some span information. This should
-        // only occur very early in the compiler pipeline.
-        // FIXME(eddyb) this should just be using `tcx.def_span(impl_def_id)`
-        let parent_def_id = self.tcx.parent_def_id(impl_def_id).unwrap();
-        let path = self.print_item_path(parent_def_id);
-        let hir_id = self.tcx.hir().as_local_hir_id(impl_def_id).unwrap();
-        let item = self.tcx.hir().expect_item_by_hir_id(hir_id);
-        let span_str = self.tcx.sess.source_map().span_to_string(item.span);
-        self.path_append(path, &format!("<impl at {}>", span_str))
-    }
 }
 
 impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
@@ -291,6 +266,9 @@ pub trait ItemPathPrinter: Sized {
     fn print_item_path(self: &mut PrintCx<'_, '_, '_, Self>, def_id: DefId) -> Self::Path {
         self.default_print_item_path(def_id)
     }
+    fn print_impl_path(self: &mut PrintCx<'_, '_, '_, Self>, impl_def_id: DefId) -> Self::Path {
+        self.default_print_impl_path(impl_def_id)
+    }
 
     fn path_crate(self: &mut PrintCx<'_, '_, '_, Self>, cnum: CrateNum) -> Self::Path;
     fn path_impl(self: &mut PrintCx<'_, '_, '_, Self>, text: &str) -> Self::Path;
@@ -470,6 +448,28 @@ impl ItemPathPrinter for LocalPathPrinter {
         self.try_print_visible_item_path(def_id)
             .unwrap_or_else(|| self.default_print_item_path(def_id))
     }
+    fn print_impl_path(self: &mut PrintCx<'_, '_, '_, Self>, impl_def_id: DefId) -> Self::Path {
+        // Always use types for non-local impls, where types are always
+        // available, and filename/line-number is mostly uninteresting.
+        let use_types = !impl_def_id.is_local() || {
+            // Otherwise, use filename/line-number if forced.
+            let force_no_types = FORCE_IMPL_FILENAME_LINE.with(|f| f.get());
+            !force_no_types
+        };
+
+        if !use_types {
+            // If no type info is available, fall back to
+            // pretty printing some span information. This should
+            // only occur very early in the compiler pipeline.
+            // FIXME(eddyb) this should just be using `tcx.def_span(impl_def_id)`
+            let parent_def_id = self.tcx.parent_def_id(impl_def_id).unwrap();
+            let path = self.print_item_path(parent_def_id);
+            let span = self.tcx.def_span(impl_def_id);
+            return self.path_append(path, &format!("<impl at {:?}>", span));
+        }
+
+        self.default_print_impl_path(impl_def_id)
+    }
 
     fn path_crate(self: &mut PrintCx<'_, '_, '_, Self>, cnum: CrateNum) -> Self::Path {
         if cnum == LOCAL_CRATE {