Skip to content

Commit 96c6398

Browse files
authored
Rollup merge of #68913 - Areredify:gat_pretty, r=cramertj
Pretty-print generic params and where clauses on associated types closes #67509
2 parents ea48820 + bf82582 commit 96c6398

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

src/librustc_ast_pretty/pprust.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1074,12 +1074,15 @@ impl<'a> State<'a> {
10741074
fn print_associated_type(
10751075
&mut self,
10761076
ident: ast::Ident,
1077+
generics: &ast::Generics,
10771078
bounds: &ast::GenericBounds,
10781079
ty: Option<&ast::Ty>,
10791080
) {
10801081
self.word_space("type");
10811082
self.print_ident(ident);
1083+
self.print_generic_params(&generics.params);
10821084
self.print_type_bounds(":", bounds);
1085+
self.print_where_clause(&generics.where_clause);
10831086
if let Some(ty) = ty {
10841087
self.s.space();
10851088
self.word_space("=");
@@ -1474,7 +1477,7 @@ impl<'a> State<'a> {
14741477
self.print_fn_full(sig, item.ident, &item.generics, &item.vis, body, &item.attrs);
14751478
}
14761479
ast::AssocItemKind::TyAlias(bounds, ty) => {
1477-
self.print_associated_type(item.ident, bounds, ty.as_deref());
1480+
self.print_associated_type(item.ident, &item.generics, bounds, ty.as_deref());
14781481
}
14791482
ast::AssocItemKind::Macro(mac) => {
14801483
self.print_mac(mac);

src/librustc_hir/print.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,17 @@ impl<'a> State<'a> {
454454
fn print_associated_type(
455455
&mut self,
456456
ident: ast::Ident,
457+
generics: &hir::Generics<'_>,
457458
bounds: Option<hir::GenericBounds<'_>>,
458459
ty: Option<&hir::Ty<'_>>,
459460
) {
460461
self.word_space("type");
461462
self.print_ident(ident);
463+
self.print_generic_params(&generics.params);
462464
if let Some(bounds) = bounds {
463465
self.print_bounds(":", bounds);
464466
}
467+
self.print_where_clause(&generics.where_clause);
465468
if let Some(ty) = ty {
466469
self.s.space();
467470
self.word_space("=");
@@ -902,6 +905,7 @@ impl<'a> State<'a> {
902905
hir::TraitItemKind::Type(ref bounds, ref default) => {
903906
self.print_associated_type(
904907
ti.ident,
908+
&ti.generics,
905909
Some(bounds),
906910
default.as_ref().map(|ty| &**ty),
907911
);
@@ -930,7 +934,7 @@ impl<'a> State<'a> {
930934
self.ann.nested(self, Nested::Body(body));
931935
}
932936
hir::ImplItemKind::TyAlias(ref ty) => {
933-
self.print_associated_type(ii.ident, None, Some(ty));
937+
self.print_associated_type(ii.ident, &ii.generics, None, Some(ty));
934938
}
935939
hir::ImplItemKind::OpaqueTy(bounds) => {
936940
self.word_space("type");

src/test/pretty/gat-bounds.pp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Check that associated types print generic parameters and where clauses.
2+
// See issue #67509.
3+
4+
// pretty-compare-only
5+
// pp-exact:gat-bounds.pp
6+
7+
#![feature(generic_associated_types)]
8+
9+
trait X {
10+
type
11+
Y<T>: Trait
12+
where
13+
Self: Sized;
14+
}
15+
16+
impl X for () {
17+
type
18+
Y<T>
19+
where
20+
Self: Sized
21+
=
22+
u32;
23+
}
24+
25+
fn main() { }

src/test/pretty/gat-bounds.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Check that associated types print generic parameters and where clauses.
2+
// See issue #67509.
3+
4+
// pretty-compare-only
5+
// pp-exact:gat-bounds.pp
6+
7+
#![feature(generic_associated_types)]
8+
9+
trait X {
10+
type Y<T>: Trait where Self: Sized;
11+
}
12+
13+
impl X for () {
14+
type Y<T> where Self: Sized = u32;
15+
}
16+
17+
fn main() { }

0 commit comments

Comments
 (0)