Skip to content

Commit 5c023d6

Browse files
committed
Improve pretty-printing for compound qualified paths.
1 parent e188e2d commit 5c023d6

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/librustc/hir/print.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,17 @@ impl<'a> State<'a> {
15231523
colons_before_params)
15241524
}
15251525
hir::QPath::TypeRelative(ref qself, ref item_segment) => {
1526-
self.print_type(qself);
1526+
// If we've got a compound-qualified-path, let's push an additional pair of angle
1527+
// brackets, so that we pretty-print `<<A::B>::C>` as `<A::B>::C`, instead of just
1528+
// `A::B::C` (since the latter could be ambiguous to the user)
1529+
if let hir::TyKind::Path(hir::QPath::Resolved(None, _)) = &qself.kind {
1530+
self.print_type(qself);
1531+
} else {
1532+
self.s.word("<");
1533+
self.print_type(qself);
1534+
self.s.word(">");
1535+
}
1536+
15271537
self.s.word("::");
15281538
self.print_ident(item_segment.ident);
15291539
self.print_generic_args(item_segment.generic_args(),

src/test/ui/qualified/qualified-path-params.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl S {
1818
fn main() {
1919
match 10 {
2020
<S as Tr>::A::f::<u8> => {}
21-
//~^ ERROR expected unit struct, unit variant or constant, found method `<S as Tr>::A::f<u8>`
21+
//~^ ERROR expected unit struct, unit variant or constant, found method `<<S as Tr>::A>::f<u8>`
2222
0 ..= <S as Tr>::A::f::<u8> => {} //~ ERROR only char and numeric types are allowed in range
2323
}
2424
}

src/test/ui/qualified/qualified-path-params.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0533]: expected unit struct, unit variant or constant, found method `<S as Tr>::A::f<u8>`
1+
error[E0533]: expected unit struct, unit variant or constant, found method `<<S as Tr>::A>::f<u8>`
22
--> $DIR/qualified-path-params.rs:20:9
33
|
44
LL | <S as Tr>::A::f::<u8> => {}

0 commit comments

Comments
 (0)