about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPatryk Wychowaniec <wychowaniec.patryk@gmail.com>2019-10-27 16:43:42 +0100
committerPatryk Wychowaniec <wychowaniec.patryk@gmail.com>2019-10-28 18:44:08 +0100
commit5c023d68d8b54d651e1775a69e999503ae5b2b30 (patch)
tree0086a3142b742a8db84befb859b3f0e90dd8804d /src
parente188e2db8471aba78c912ef77e222beceb2ea532 (diff)
downloadrust-5c023d68d8b54d651e1775a69e999503ae5b2b30.tar.gz
rust-5c023d68d8b54d651e1775a69e999503ae5b2b30.zip
Improve pretty-printing for compound qualified paths.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/hir/print.rs12
-rw-r--r--src/test/ui/qualified/qualified-path-params.rs2
-rw-r--r--src/test/ui/qualified/qualified-path-params.stderr2
3 files changed, 13 insertions, 3 deletions
diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs
index b6001c30cb0..64b355f6ec9 100644
--- a/src/librustc/hir/print.rs
+++ b/src/librustc/hir/print.rs
@@ -1523,7 +1523,17 @@ impl<'a> State<'a> {
                                         colons_before_params)
             }
             hir::QPath::TypeRelative(ref qself, ref item_segment) => {
-                self.print_type(qself);
+                // If we've got a compound-qualified-path, let's push an additional pair of angle
+                // brackets, so that we pretty-print `<<A::B>::C>` as `<A::B>::C`, instead of just
+                // `A::B::C` (since the latter could be ambiguous to the user)
+                if let hir::TyKind::Path(hir::QPath::Resolved(None, _)) = &qself.kind {
+                    self.print_type(qself);
+                } else {
+                    self.s.word("<");
+                    self.print_type(qself);
+                    self.s.word(">");
+                }
+
                 self.s.word("::");
                 self.print_ident(item_segment.ident);
                 self.print_generic_args(item_segment.generic_args(),
diff --git a/src/test/ui/qualified/qualified-path-params.rs b/src/test/ui/qualified/qualified-path-params.rs
index 27cad33b553..b1b60b4b73f 100644
--- a/src/test/ui/qualified/qualified-path-params.rs
+++ b/src/test/ui/qualified/qualified-path-params.rs
@@ -18,7 +18,7 @@ impl S {
 fn main() {
     match 10 {
         <S as Tr>::A::f::<u8> => {}
-    //~^ ERROR expected unit struct, unit variant or constant, found method `<S as Tr>::A::f<u8>`
+    //~^ ERROR expected unit struct, unit variant or constant, found method `<<S as Tr>::A>::f<u8>`
         0 ..= <S as Tr>::A::f::<u8> => {} //~ ERROR only char and numeric types are allowed in range
     }
 }
diff --git a/src/test/ui/qualified/qualified-path-params.stderr b/src/test/ui/qualified/qualified-path-params.stderr
index 54e34b50806..92792f2e86a 100644
--- a/src/test/ui/qualified/qualified-path-params.stderr
+++ b/src/test/ui/qualified/qualified-path-params.stderr
@@ -1,4 +1,4 @@
-error[E0533]: expected unit struct, unit variant or constant, found method `<S as Tr>::A::f<u8>`
+error[E0533]: expected unit struct, unit variant or constant, found method `<<S as Tr>::A>::f<u8>`
   --> $DIR/qualified-path-params.rs:20:9
    |
 LL |         <S as Tr>::A::f::<u8> => {}