Skip to content

Commit

Permalink
deps: apply rustc-ap v705 changes to itemkind variants
Browse files Browse the repository at this point in the history
  • Loading branch information
calebcartwright committed Feb 7, 2021
1 parent b80fdf2 commit 9ed7511
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 162 deletions.
140 changes: 69 additions & 71 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,8 @@ impl<'a> FmtVisitor<'a> {
use crate::ast::AssocItemKind::*;
fn need_empty_line(a: &ast::AssocItemKind, b: &ast::AssocItemKind) -> bool {
match (a, b) {
(TyAlias(_, _, _, ref lty), TyAlias(_, _, _, ref rty))
if both_type(lty, rty) || both_opaque(lty, rty) =>
(TyAlias(lty), TyAlias(rty))
if both_type(&lty.3, &rty.3) || both_opaque(&lty.3, &rty.3) =>
{
false
}
Expand All @@ -629,17 +629,17 @@ impl<'a> FmtVisitor<'a> {
}

buffer.sort_by(|(_, a), (_, b)| match (&a.kind, &b.kind) {
(TyAlias(_, _, _, ref lty), TyAlias(_, _, _, ref rty))
if both_type(lty, rty) || both_opaque(lty, rty) =>
(TyAlias(lty), TyAlias(rty))
if both_type(&lty.3, &rty.3) || both_opaque(&lty.3, &rty.3) =>
{
a.ident.as_str().cmp(&b.ident.as_str())
}
(Const(..), Const(..)) | (MacCall(..), MacCall(..)) => {
a.ident.as_str().cmp(&b.ident.as_str())
}
(Fn(..), Fn(..)) => a.span.lo().cmp(&b.span.lo()),
(TyAlias(_, _, _, ref ty), _) if is_type(ty) => Ordering::Less,
(_, TyAlias(_, _, _, ref ty)) if is_type(ty) => Ordering::Greater,
(TyAlias(ty), _) if is_type(&ty.3) => Ordering::Less,
(_, TyAlias(ty)) if is_type(&ty.3) => Ordering::Greater,
(TyAlias(..), _) => Ordering::Less,
(_, TyAlias(..)) => Ordering::Greater,
(Const(..), _) => Ordering::Less,
Expand Down Expand Up @@ -675,13 +675,13 @@ pub(crate) fn format_impl(
item: &ast::Item,
offset: Indent,
) -> Option<String> {
if let ast::ItemKind::Impl {
ref generics,
ref self_ty,
ref items,
..
} = item.kind
{
if let ast::ItemKind::Impl(impl_kind) = &item.kind {
let ast::ImplKind {
ref generics,
ref self_ty,
ref items,
..
} = **impl_kind;
let mut result = String::with_capacity(128);
let ref_and_type = format_impl_ref_and_type(context, item, offset)?;
let sep = offset.to_string_with_newline(context.config);
Expand Down Expand Up @@ -829,17 +829,17 @@ fn format_impl_ref_and_type(
item: &ast::Item,
offset: Indent,
) -> Option<String> {
if let ast::ItemKind::Impl {
unsafety,
polarity,
defaultness,
constness,
ref generics,
of_trait: ref trait_ref,
ref self_ty,
..
} = item.kind
{
if let ast::ItemKind::Impl(impl_kind) = &item.kind {
let ast::ImplKind {
unsafety,
polarity,
defaultness,
constness,
ref generics,
of_trait: ref trait_ref,
ref self_ty,
..
} = **impl_kind;
let mut result = String::with_capacity(128);

result.push_str(&format_visibility(context, &item.vis));
Expand Down Expand Up @@ -1025,14 +1025,9 @@ pub(crate) fn format_trait(
item: &ast::Item,
offset: Indent,
) -> Option<String> {
if let ast::ItemKind::Trait(
is_auto,
unsafety,
ref generics,
ref generic_bounds,
ref trait_items,
) = item.kind
{
if let ast::ItemKind::Trait(trait_kind) = &item.kind {
let ast::TraitKind(is_auto, unsafety, ref generics, ref generic_bounds, ref trait_items) =
**trait_kind;
let mut result = String::with_capacity(128);
let header = format!(
"{}{}{}trait ",
Expand Down Expand Up @@ -3119,31 +3114,35 @@ impl Rewrite for ast::ForeignItem {
let span = mk_sp(self.span.lo(), self.span.hi() - BytePos(1));

let item_str = match self.kind {
ast::ForeignItemKind::Fn(defaultness, ref fn_sig, ref generics, Some(ref body)) => {
let mut visitor = FmtVisitor::from_context(context);
visitor.block_indent = shape.indent;
visitor.last_pos = self.span.lo();
let inner_attrs = inner_attributes(&self.attrs);
let fn_ctxt = visit::FnCtxt::Foreign;
visitor.visit_fn(
visit::FnKind::Fn(fn_ctxt, self.ident, &fn_sig, &self.vis, Some(body)),
generics,
&fn_sig.decl,
self.span,
defaultness,
Some(&inner_attrs),
);
Some(visitor.buffer.to_owned())
ast::ForeignItemKind::Fn(ref fn_kind) => {
let ast::FnKind(defaultness, ref fn_sig, ref generics, ref block) = **fn_kind;
if let Some(ref body) = block {
let mut visitor = FmtVisitor::from_context(context);
visitor.block_indent = shape.indent;
visitor.last_pos = self.span.lo();
let inner_attrs = inner_attributes(&self.attrs);
let fn_ctxt = visit::FnCtxt::Foreign;
visitor.visit_fn(
visit::FnKind::Fn(fn_ctxt, self.ident, &fn_sig, &self.vis, Some(body)),
generics,
&fn_sig.decl,
self.span,
defaultness,
Some(&inner_attrs),
);
Some(visitor.buffer.to_owned())
} else {
rewrite_fn_base(
context,
shape.indent,
self.ident,
&FnSig::from_method_sig(&fn_sig, generics, self.vis.clone()),
span,
FnBraceStyle::None,
)
.map(|(s, _, _)| format!("{};", s))
}
}
ast::ForeignItemKind::Fn(_, ref fn_sig, ref generics, None) => rewrite_fn_base(
context,
shape.indent,
self.ident,
&FnSig::from_method_sig(&fn_sig, generics, self.vis.clone()),
span,
FnBraceStyle::None,
)
.map(|(s, _, _)| format!("{};", s)),
ast::ForeignItemKind::Static(ref ty, mutability, _) => {
// FIXME(#21): we're dropping potential comments in between the
// function kw here.
Expand All @@ -3158,21 +3157,20 @@ impl Rewrite for ast::ForeignItem {
// 1 = ;
rewrite_assign_rhs(context, prefix, &**ty, shape.sub_width(1)?).map(|s| s + ";")
}
ast::ForeignItemKind::TyAlias(
_,
ref generics,
ref generic_bounds,
ref type_default,
) => rewrite_type_alias(
self.ident,
type_default.as_ref(),
generics,
Some(generic_bounds),
&context,
shape.indent,
&self.vis,
self.span,
),
ast::ForeignItemKind::TyAlias(ref ty_alias_kind) => {
let ast::TyAliasKind(_, ref generics, ref generic_bounds, ref type_default) =
**ty_alias_kind;
rewrite_type_alias(
self.ident,
type_default.as_ref(),
generics,
Some(generic_bounds),
&context,
shape.indent,
&self.vis,
self.span,
)
}
ast::ForeignItemKind::MacCall(ref mac) => {
rewrite_macro(mac, None, context, shape, MacroPosition::Item)
}
Expand Down

0 comments on commit 9ed7511

Please sign in to comment.