Skip to content

Commit

Permalink
Improve pretty-printing for compound qualified paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
Patryk27 committed Oct 27, 2019
1 parent 97b10b7 commit 1c5d0be
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/librustc/hir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/qualified/qualified-path-params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl S {
fn main() {
match 10 {
<S as Tr>::A::f::<u8> => {}
//~^ ERROR expected unit struct/variant or constant, found method `<S as Tr>::A::f<u8>`
//~^ ERROR expected unit struct/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
}
}
2 changes: 1 addition & 1 deletion src/test/ui/qualified/qualified-path-params.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0533]: expected unit struct/variant or constant, found method `<S as Tr>::A::f<u8>`
error[E0533]: expected unit struct/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> => {}
Expand Down

0 comments on commit 1c5d0be

Please sign in to comment.