Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretty-print generic params and where clauses on associated types #68913

Merged
merged 3 commits into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/librustc_ast_pretty/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1074,12 +1074,15 @@ impl<'a> State<'a> {
fn print_associated_type(
&mut self,
ident: ast::Ident,
generics: &ast::Generics,
bounds: &ast::GenericBounds,
ty: Option<&ast::Ty>,
) {
self.word_space("type");
self.print_ident(ident);
self.print_generic_params(&generics.params);
self.print_type_bounds(":", bounds);
self.print_where_clause(&generics.where_clause);
if let Some(ty) = ty {
self.s.space();
self.word_space("=");
Expand Down Expand Up @@ -1474,7 +1477,7 @@ impl<'a> State<'a> {
self.print_fn_full(sig, item.ident, &item.generics, &item.vis, body, &item.attrs);
}
ast::AssocItemKind::TyAlias(bounds, ty) => {
self.print_associated_type(item.ident, bounds, ty.as_deref());
self.print_associated_type(item.ident, &item.generics, bounds, ty.as_deref());
}
ast::AssocItemKind::Macro(mac) => {
self.print_mac(mac);
Expand Down
6 changes: 5 additions & 1 deletion src/librustc_hir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,17 @@ impl<'a> State<'a> {
fn print_associated_type(
&mut self,
ident: ast::Ident,
generics: &hir::Generics<'_>,
bounds: Option<hir::GenericBounds<'_>>,
ty: Option<&hir::Ty<'_>>,
) {
self.word_space("type");
self.print_ident(ident);
self.print_generic_params(&generics.params);
if let Some(bounds) = bounds {
self.print_bounds(":", bounds);
}
self.print_where_clause(&generics.where_clause);
if let Some(ty) = ty {
self.s.space();
self.word_space("=");
Expand Down Expand Up @@ -902,6 +905,7 @@ impl<'a> State<'a> {
hir::TraitItemKind::Type(ref bounds, ref default) => {
self.print_associated_type(
ti.ident,
&ti.generics,
Some(bounds),
default.as_ref().map(|ty| &**ty),
);
Expand Down Expand Up @@ -930,7 +934,7 @@ impl<'a> State<'a> {
self.ann.nested(self, Nested::Body(body));
}
hir::ImplItemKind::TyAlias(ref ty) => {
self.print_associated_type(ii.ident, None, Some(ty));
self.print_associated_type(ii.ident, &ii.generics, None, Some(ty));
}
hir::ImplItemKind::OpaqueTy(bounds) => {
self.word_space("type");
Expand Down
25 changes: 25 additions & 0 deletions src/test/pretty/gat-bounds.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Check that associated types print generic parameters and where clauses.
// See issue #67509.

// pretty-compare-only
// pp-exact:gat-bounds.pp

#![feature(generic_associated_types)]

trait X {
type
Y<T>: Trait
where
Self: Sized;
}

impl X for () {
type
Y<T>
where
Self: Sized
=
u32;
}

fn main() { }
17 changes: 17 additions & 0 deletions src/test/pretty/gat-bounds.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Check that associated types print generic parameters and where clauses.
// See issue #67509.

// pretty-compare-only
// pp-exact:gat-bounds.pp

#![feature(generic_associated_types)]

trait X {
type Y<T>: Trait where Self: Sized;
}

impl X for () {
type Y<T> where Self: Sized = u32;
}

fn main() { }