about summary refs log tree commit diff
path: root/src/test/ui/hygiene
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 /src/test/ui/hygiene
parent7b2deb562822112cc30d23958e7459564e2c6ef9 (diff)
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 'src/test/ui/hygiene')
-rw-r--r--src/test/ui/hygiene/fields.rs4
-rw-r--r--src/test/ui/hygiene/fields.stderr4
-rw-r--r--src/test/ui/hygiene/intercrate.rs2
-rw-r--r--src/test/ui/hygiene/intercrate.stderr2
-rw-r--r--src/test/ui/hygiene/nested_macro_privacy.rs2
-rw-r--r--src/test/ui/hygiene/nested_macro_privacy.stderr2
6 files changed, 8 insertions, 8 deletions
diff --git a/src/test/ui/hygiene/fields.rs b/src/test/ui/hygiene/fields.rs
index 597019cb1ee..7a417b46fcc 100644
--- a/src/test/ui/hygiene/fields.rs
+++ b/src/test/ui/hygiene/fields.rs
@@ -15,8 +15,8 @@ mod foo {
         let s = S { x: 0 }; //~ ERROR type `foo::S` is private
         let _ = s.x; //~ ERROR type `foo::S` is private
 
-        let t = T(0); //~ ERROR type `foo::T` is private
-        let _ = t.0; //~ ERROR type `foo::T` is private
+        let t = T(0); //~ ERROR type `T` is private
+        let _ = t.0; //~ ERROR type `T` is private
 
         let s = $S { $x: 0, x: 1 };
         assert_eq!((s.$x, s.x), (0, 1));
diff --git a/src/test/ui/hygiene/fields.stderr b/src/test/ui/hygiene/fields.stderr
index 6d784408016..3666aeabfa7 100644
--- a/src/test/ui/hygiene/fields.stderr
+++ b/src/test/ui/hygiene/fields.stderr
@@ -20,7 +20,7 @@ LL |     let s = foo::m!(S, x);
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error: type `foo::T` is private
+error: type `T` is private
   --> $DIR/fields.rs:18:17
    |
 LL |         let t = T(0);
@@ -31,7 +31,7 @@ LL |     let s = foo::m!(S, x);
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error: type `foo::T` is private
+error: type `T` is private
   --> $DIR/fields.rs:19:17
    |
 LL |         let _ = t.0;
diff --git a/src/test/ui/hygiene/intercrate.rs b/src/test/ui/hygiene/intercrate.rs
index 2acbc893cf5..d9b5b789e4a 100644
--- a/src/test/ui/hygiene/intercrate.rs
+++ b/src/test/ui/hygiene/intercrate.rs
@@ -8,5 +8,5 @@ extern crate intercrate;
 
 fn main() {
     assert_eq!(intercrate::foo::m!(), 1);
-    //~^ ERROR type `fn() -> u32 {intercrate::foo::bar::f}` is private
+    //~^ ERROR type `fn() -> u32 {foo::bar::f}` is private
 }
diff --git a/src/test/ui/hygiene/intercrate.stderr b/src/test/ui/hygiene/intercrate.stderr
index c27ba74a263..cd593abf530 100644
--- a/src/test/ui/hygiene/intercrate.stderr
+++ b/src/test/ui/hygiene/intercrate.stderr
@@ -1,4 +1,4 @@
-error: type `fn() -> u32 {intercrate::foo::bar::f}` is private
+error: type `fn() -> u32 {foo::bar::f}` is private
   --> $DIR/intercrate.rs:10:16
    |
 LL |     assert_eq!(intercrate::foo::m!(), 1);
diff --git a/src/test/ui/hygiene/nested_macro_privacy.rs b/src/test/ui/hygiene/nested_macro_privacy.rs
index bee90e2bb88..dea9101ee00 100644
--- a/src/test/ui/hygiene/nested_macro_privacy.rs
+++ b/src/test/ui/hygiene/nested_macro_privacy.rs
@@ -12,6 +12,6 @@ n!(foo, S, i, m);
 
 fn main() {
     use foo::{S, m};
-    S::default().i; //~ ERROR field `i` of struct `foo::S` is private
+    S::default().i; //~ ERROR field `i` of struct `S` is private
     m!(S::default()); // ok
 }
diff --git a/src/test/ui/hygiene/nested_macro_privacy.stderr b/src/test/ui/hygiene/nested_macro_privacy.stderr
index 482957a3264..1d11cd0f571 100644
--- a/src/test/ui/hygiene/nested_macro_privacy.stderr
+++ b/src/test/ui/hygiene/nested_macro_privacy.stderr
@@ -1,4 +1,4 @@
-error[E0616]: field `i` of struct `foo::S` is private
+error[E0616]: field `i` of struct `S` is private
   --> $DIR/nested_macro_privacy.rs:15:18
    |
 LL |     S::default().i;