diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index b6001c30cb030..64b355f6ec9d1 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 `<::C>` as `::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 aefec2e76732a..ea2ae0e86bf64 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 { ::A::f:: => {} - //~^ ERROR expected unit struct/variant or constant, found method `::A::f` + //~^ ERROR expected unit struct/variant or constant, found method `<::A>::f` 0 ..= ::A::f:: => {} //~ 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 b0cd3eb8947ea..3e8fcdc7ca3e2 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/variant or constant, found method `::A::f` +error[E0533]: expected unit struct/variant or constant, found method `<::A>::f` --> $DIR/qualified-path-params.rs:20:9 | LL | ::A::f:: => {}