AST: Refactor type alias where clauses
This commit is contained in:
parent
4026fd735c
commit
fc64cbdbe7
30
src/items.rs
30
src/items.rs
@ -1651,8 +1651,7 @@ struct TyAliasRewriteInfo<'c, 'g>(
|
|||||||
&'c RewriteContext<'c>,
|
&'c RewriteContext<'c>,
|
||||||
Indent,
|
Indent,
|
||||||
&'g ast::Generics,
|
&'g ast::Generics,
|
||||||
(ast::TyAliasWhereClause, ast::TyAliasWhereClause),
|
ast::TyAliasWhereClauses,
|
||||||
usize,
|
|
||||||
symbol::Ident,
|
symbol::Ident,
|
||||||
Span,
|
Span,
|
||||||
);
|
);
|
||||||
@ -1672,7 +1671,6 @@ pub(crate) fn rewrite_type_alias<'a, 'b>(
|
|||||||
ref bounds,
|
ref bounds,
|
||||||
ref ty,
|
ref ty,
|
||||||
where_clauses,
|
where_clauses,
|
||||||
where_predicates_split,
|
|
||||||
} = *ty_alias_kind;
|
} = *ty_alias_kind;
|
||||||
let ty_opt = ty.as_ref();
|
let ty_opt = ty.as_ref();
|
||||||
let (ident, vis) = match visitor_kind {
|
let (ident, vis) = match visitor_kind {
|
||||||
@ -1680,15 +1678,7 @@ pub(crate) fn rewrite_type_alias<'a, 'b>(
|
|||||||
AssocTraitItem(i) | AssocImplItem(i) => (i.ident, &i.vis),
|
AssocTraitItem(i) | AssocImplItem(i) => (i.ident, &i.vis),
|
||||||
ForeignItem(i) => (i.ident, &i.vis),
|
ForeignItem(i) => (i.ident, &i.vis),
|
||||||
};
|
};
|
||||||
let rw_info = &TyAliasRewriteInfo(
|
let rw_info = &TyAliasRewriteInfo(context, indent, generics, where_clauses, ident, span);
|
||||||
context,
|
|
||||||
indent,
|
|
||||||
generics,
|
|
||||||
where_clauses,
|
|
||||||
where_predicates_split,
|
|
||||||
ident,
|
|
||||||
span,
|
|
||||||
);
|
|
||||||
let op_ty = opaque_ty(ty);
|
let op_ty = opaque_ty(ty);
|
||||||
// Type Aliases are formatted slightly differently depending on the context
|
// Type Aliases are formatted slightly differently depending on the context
|
||||||
// in which they appear, whether they are opaque, and whether they are associated.
|
// in which they appear, whether they are opaque, and whether they are associated.
|
||||||
@ -1724,19 +1714,11 @@ fn rewrite_ty<R: Rewrite>(
|
|||||||
vis: &ast::Visibility,
|
vis: &ast::Visibility,
|
||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
let mut result = String::with_capacity(128);
|
let mut result = String::with_capacity(128);
|
||||||
let TyAliasRewriteInfo(
|
let TyAliasRewriteInfo(context, indent, generics, where_clauses, ident, span) = *rw_info;
|
||||||
context,
|
|
||||||
indent,
|
|
||||||
generics,
|
|
||||||
where_clauses,
|
|
||||||
where_predicates_split,
|
|
||||||
ident,
|
|
||||||
span,
|
|
||||||
) = *rw_info;
|
|
||||||
let (before_where_predicates, after_where_predicates) = generics
|
let (before_where_predicates, after_where_predicates) = generics
|
||||||
.where_clause
|
.where_clause
|
||||||
.predicates
|
.predicates
|
||||||
.split_at(where_predicates_split);
|
.split_at(where_clauses.split);
|
||||||
if !after_where_predicates.is_empty() {
|
if !after_where_predicates.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
@ -1771,7 +1753,7 @@ fn rewrite_ty<R: Rewrite>(
|
|||||||
let where_clause_str = rewrite_where_clause(
|
let where_clause_str = rewrite_where_clause(
|
||||||
context,
|
context,
|
||||||
before_where_predicates,
|
before_where_predicates,
|
||||||
where_clauses.0.1,
|
where_clauses.before.span,
|
||||||
context.config.brace_style(),
|
context.config.brace_style(),
|
||||||
Shape::legacy(where_budget, indent),
|
Shape::legacy(where_budget, indent),
|
||||||
false,
|
false,
|
||||||
@ -1795,7 +1777,7 @@ fn rewrite_ty<R: Rewrite>(
|
|||||||
let comment_span = context
|
let comment_span = context
|
||||||
.snippet_provider
|
.snippet_provider
|
||||||
.opt_span_before(span, "=")
|
.opt_span_before(span, "=")
|
||||||
.map(|op_lo| mk_sp(where_clauses.0.1.hi(), op_lo));
|
.map(|op_lo| mk_sp(where_clauses.before.span.hi(), op_lo));
|
||||||
|
|
||||||
let lhs = match comment_span {
|
let lhs = match comment_span {
|
||||||
Some(comment_span)
|
Some(comment_span)
|
||||||
|
Loading…
Reference in New Issue
Block a user