about summary refs log tree commit diff
path: root/compiler/rustc_save_analysis/src
diff options
context:
space:
mode:
authorDan Aloni <alonid@gmail.com>2020-09-02 10:40:56 +0300
committerDan Aloni <alonid@gmail.com>2020-09-02 22:26:37 +0300
commit07e7823c01be1733df2480de19fbbe6b8e9384cf (patch)
tree9e4ff1075680201f9c72b58bf780638ef1fcede3 /compiler/rustc_save_analysis/src
parent7b2deb562822112cc30d23958e7459564e2c6ef9 (diff)
downloadrust-07e7823c01be1733df2480de19fbbe6b8e9384cf.tar.gz
rust-07e7823c01be1733df2480de19fbbe6b8e9384cf.zip
pretty: trim paths of unique symbols
If a symbol name can only be imported from one place for a type, and
as long as it was not glob-imported anywhere in the current crate, we
can trim its printed path and print only the name.

This has wide implications on error messages with types, for example,
shortening `std::vec::Vec` to just `Vec`, as long as there is no other
`Vec` importable anywhere.

This adds a new '-Z trim-diagnostic-paths=false' option to control this
feature.

On the good path, with no diagnosis printed, we should try to avoid
issuing this query, so we need to prevent trimmed_def_paths query on
several cases.

This change also relies on a previous commit that differentiates
between `Debug` and `Display` on various rustc types, where the latter
is trimmed and presented to the user and the former is not.
Diffstat (limited to 'compiler/rustc_save_analysis/src')
-rw-r--r--compiler/rustc_save_analysis/src/lib.rs48
1 files changed, 25 insertions, 23 deletions
diff --git a/compiler/rustc_save_analysis/src/lib.rs b/compiler/rustc_save_analysis/src/lib.rs
index 629051c1820..a12eb264065 100644
--- a/compiler/rustc_save_analysis/src/lib.rs
+++ b/compiler/rustc_save_analysis/src/lib.rs
@@ -21,7 +21,7 @@ use rustc_hir_pretty::{enum_def_to_string, fn_to_string, ty_to_string};
 use rustc_middle::hir::map::Map;
 use rustc_middle::middle::cstore::ExternCrate;
 use rustc_middle::middle::privacy::AccessLevels;
-use rustc_middle::ty::{self, DefIdTree, TyCtxt};
+use rustc_middle::ty::{self, print::with_no_trimmed_paths, DefIdTree, TyCtxt};
 use rustc_middle::{bug, span_bug};
 use rustc_session::config::{CrateType, Input, OutputType};
 use rustc_session::output::{filename_for_metadata, out_filename};
@@ -989,32 +989,34 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
     config: Option<Config>,
     mut handler: H,
 ) {
-    tcx.dep_graph.with_ignore(|| {
-        info!("Dumping crate {}", cratename);
-
-        // Privacy checking requires and is done after type checking; use a
-        // fallback in case the access levels couldn't have been correctly computed.
-        let access_levels = match tcx.sess.compile_status() {
-            Ok(..) => tcx.privacy_access_levels(LOCAL_CRATE),
-            Err(..) => tcx.arena.alloc(AccessLevels::default()),
-        };
+    with_no_trimmed_paths(|| {
+        tcx.dep_graph.with_ignore(|| {
+            info!("Dumping crate {}", cratename);
+
+            // Privacy checking requires and is done after type checking; use a
+            // fallback in case the access levels couldn't have been correctly computed.
+            let access_levels = match tcx.sess.compile_status() {
+                Ok(..) => tcx.privacy_access_levels(LOCAL_CRATE),
+                Err(..) => tcx.arena.alloc(AccessLevels::default()),
+            };
 
-        let save_ctxt = SaveContext {
-            tcx,
-            maybe_typeck_results: None,
-            access_levels: &access_levels,
-            span_utils: SpanUtils::new(&tcx.sess),
-            config: find_config(config),
-            impl_counter: Cell::new(0),
-        };
+            let save_ctxt = SaveContext {
+                tcx,
+                maybe_typeck_results: None,
+                access_levels: &access_levels,
+                span_utils: SpanUtils::new(&tcx.sess),
+                config: find_config(config),
+                impl_counter: Cell::new(0),
+            };
 
-        let mut visitor = DumpVisitor::new(save_ctxt);
+            let mut visitor = DumpVisitor::new(save_ctxt);
 
-        visitor.dump_crate_info(cratename, tcx.hir().krate());
-        visitor.dump_compilation_options(input, cratename);
-        visitor.process_crate(tcx.hir().krate());
+            visitor.dump_crate_info(cratename, tcx.hir().krate());
+            visitor.dump_compilation_options(input, cratename);
+            visitor.process_crate(tcx.hir().krate());
 
-        handler.save(&visitor.save_ctxt, &visitor.analysis())
+            handler.save(&visitor.save_ctxt, &visitor.analysis())
+        })
     })
 }