Change syntax for TyAlias where clauses
This commit is contained in:
parent
379e94f5a4
commit
c20b4f5584
46 changed files with 394 additions and 255 deletions
|
@ -36,12 +36,16 @@ impl<'a> State<'a> {
|
|||
ast::ForeignItemKind::TyAlias(box ast::TyAlias {
|
||||
defaultness,
|
||||
generics,
|
||||
where_clauses,
|
||||
where_predicates_split,
|
||||
bounds,
|
||||
ty,
|
||||
}) => {
|
||||
self.print_associated_type(
|
||||
ident,
|
||||
generics,
|
||||
*where_clauses,
|
||||
*where_predicates_split,
|
||||
bounds,
|
||||
ty.as_deref(),
|
||||
vis,
|
||||
|
@ -95,11 +99,15 @@ impl<'a> State<'a> {
|
|||
&mut self,
|
||||
ident: Ident,
|
||||
generics: &ast::Generics,
|
||||
where_clauses: (ast::TyAliasWhereClause, ast::TyAliasWhereClause),
|
||||
where_predicates_split: usize,
|
||||
bounds: &ast::GenericBounds,
|
||||
ty: Option<&ast::Ty>,
|
||||
vis: &ast::Visibility,
|
||||
defaultness: ast::Defaultness,
|
||||
) {
|
||||
let (before_predicates, after_predicates) =
|
||||
generics.where_clause.predicates.split_at(where_predicates_split);
|
||||
self.head("");
|
||||
self.print_visibility(vis);
|
||||
self.print_defaultness(defaultness);
|
||||
|
@ -107,12 +115,13 @@ impl<'a> State<'a> {
|
|||
self.print_ident(ident);
|
||||
self.print_generic_params(&generics.params);
|
||||
self.print_type_bounds(":", bounds);
|
||||
self.print_where_clause(&generics.where_clause);
|
||||
self.print_where_clause_parts(where_clauses.0.0, before_predicates);
|
||||
if let Some(ty) = ty {
|
||||
self.space();
|
||||
self.word_space("=");
|
||||
self.print_type(ty);
|
||||
}
|
||||
self.print_where_clause_parts(where_clauses.1.0, after_predicates);
|
||||
self.word(";");
|
||||
self.end(); // end inner head-block
|
||||
self.end(); // end outer head-block
|
||||
|
@ -211,6 +220,8 @@ impl<'a> State<'a> {
|
|||
ast::ItemKind::TyAlias(box ast::TyAlias {
|
||||
defaultness,
|
||||
ref generics,
|
||||
where_clauses,
|
||||
where_predicates_split,
|
||||
ref bounds,
|
||||
ref ty,
|
||||
}) => {
|
||||
|
@ -218,6 +229,8 @@ impl<'a> State<'a> {
|
|||
self.print_associated_type(
|
||||
item.ident,
|
||||
generics,
|
||||
where_clauses,
|
||||
where_predicates_split,
|
||||
bounds,
|
||||
ty,
|
||||
&item.vis,
|
||||
|
@ -496,10 +509,19 @@ impl<'a> State<'a> {
|
|||
ast::AssocItemKind::Const(def, ty, body) => {
|
||||
self.print_item_const(ident, None, ty, body.as_deref(), vis, *def);
|
||||
}
|
||||
ast::AssocItemKind::TyAlias(box ast::TyAlias { defaultness, generics, bounds, ty }) => {
|
||||
ast::AssocItemKind::TyAlias(box ast::TyAlias {
|
||||
defaultness,
|
||||
generics,
|
||||
where_clauses,
|
||||
where_predicates_split,
|
||||
bounds,
|
||||
ty,
|
||||
}) => {
|
||||
self.print_associated_type(
|
||||
ident,
|
||||
generics,
|
||||
*where_clauses,
|
||||
*where_predicates_split,
|
||||
bounds,
|
||||
ty.as_deref(),
|
||||
vis,
|
||||
|
@ -566,14 +588,22 @@ impl<'a> State<'a> {
|
|||
}
|
||||
|
||||
fn print_where_clause(&mut self, where_clause: &ast::WhereClause) {
|
||||
if where_clause.predicates.is_empty() && !where_clause.has_where_token {
|
||||
self.print_where_clause_parts(where_clause.has_where_token, &where_clause.predicates);
|
||||
}
|
||||
|
||||
crate fn print_where_clause_parts(
|
||||
&mut self,
|
||||
has_where_token: bool,
|
||||
predicates: &[ast::WherePredicate],
|
||||
) {
|
||||
if predicates.is_empty() && !has_where_token {
|
||||
return;
|
||||
}
|
||||
|
||||
self.space();
|
||||
self.word_space("where");
|
||||
|
||||
for (i, predicate) in where_clause.predicates.iter().enumerate() {
|
||||
for (i, predicate) in predicates.iter().enumerate() {
|
||||
if i != 0 {
|
||||
self.word_space(",");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue