Skip to content

Commit 9ed7511

Browse files
deps: apply rustc-ap v705 changes to itemkind variants
1 parent b80fdf2 commit 9ed7511

File tree

2 files changed

+177
-162
lines changed

2 files changed

+177
-162
lines changed

Diff for: src/items.rs

+69-71
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,8 @@ impl<'a> FmtVisitor<'a> {
618618
use crate::ast::AssocItemKind::*;
619619
fn need_empty_line(a: &ast::AssocItemKind, b: &ast::AssocItemKind) -> bool {
620620
match (a, b) {
621-
(TyAlias(_, _, _, ref lty), TyAlias(_, _, _, ref rty))
622-
if both_type(lty, rty) || both_opaque(lty, rty) =>
621+
(TyAlias(lty), TyAlias(rty))
622+
if both_type(&lty.3, &rty.3) || both_opaque(&lty.3, &rty.3) =>
623623
{
624624
false
625625
}
@@ -629,17 +629,17 @@ impl<'a> FmtVisitor<'a> {
629629
}
630630

631631
buffer.sort_by(|(_, a), (_, b)| match (&a.kind, &b.kind) {
632-
(TyAlias(_, _, _, ref lty), TyAlias(_, _, _, ref rty))
633-
if both_type(lty, rty) || both_opaque(lty, rty) =>
632+
(TyAlias(lty), TyAlias(rty))
633+
if both_type(&lty.3, &rty.3) || both_opaque(&lty.3, &rty.3) =>
634634
{
635635
a.ident.as_str().cmp(&b.ident.as_str())
636636
}
637637
(Const(..), Const(..)) | (MacCall(..), MacCall(..)) => {
638638
a.ident.as_str().cmp(&b.ident.as_str())
639639
}
640640
(Fn(..), Fn(..)) => a.span.lo().cmp(&b.span.lo()),
641-
(TyAlias(_, _, _, ref ty), _) if is_type(ty) => Ordering::Less,
642-
(_, TyAlias(_, _, _, ref ty)) if is_type(ty) => Ordering::Greater,
641+
(TyAlias(ty), _) if is_type(&ty.3) => Ordering::Less,
642+
(_, TyAlias(ty)) if is_type(&ty.3) => Ordering::Greater,
643643
(TyAlias(..), _) => Ordering::Less,
644644
(_, TyAlias(..)) => Ordering::Greater,
645645
(Const(..), _) => Ordering::Less,
@@ -675,13 +675,13 @@ pub(crate) fn format_impl(
675675
item: &ast::Item,
676676
offset: Indent,
677677
) -> Option<String> {
678-
if let ast::ItemKind::Impl {
679-
ref generics,
680-
ref self_ty,
681-
ref items,
682-
..
683-
} = item.kind
684-
{
678+
if let ast::ItemKind::Impl(impl_kind) = &item.kind {
679+
let ast::ImplKind {
680+
ref generics,
681+
ref self_ty,
682+
ref items,
683+
..
684+
} = **impl_kind;
685685
let mut result = String::with_capacity(128);
686686
let ref_and_type = format_impl_ref_and_type(context, item, offset)?;
687687
let sep = offset.to_string_with_newline(context.config);
@@ -829,17 +829,17 @@ fn format_impl_ref_and_type(
829829
item: &ast::Item,
830830
offset: Indent,
831831
) -> Option<String> {
832-
if let ast::ItemKind::Impl {
833-
unsafety,
834-
polarity,
835-
defaultness,
836-
constness,
837-
ref generics,
838-
of_trait: ref trait_ref,
839-
ref self_ty,
840-
..
841-
} = item.kind
842-
{
832+
if let ast::ItemKind::Impl(impl_kind) = &item.kind {
833+
let ast::ImplKind {
834+
unsafety,
835+
polarity,
836+
defaultness,
837+
constness,
838+
ref generics,
839+
of_trait: ref trait_ref,
840+
ref self_ty,
841+
..
842+
} = **impl_kind;
843843
let mut result = String::with_capacity(128);
844844

845845
result.push_str(&format_visibility(context, &item.vis));
@@ -1025,14 +1025,9 @@ pub(crate) fn format_trait(
10251025
item: &ast::Item,
10261026
offset: Indent,
10271027
) -> Option<String> {
1028-
if let ast::ItemKind::Trait(
1029-
is_auto,
1030-
unsafety,
1031-
ref generics,
1032-
ref generic_bounds,
1033-
ref trait_items,
1034-
) = item.kind
1035-
{
1028+
if let ast::ItemKind::Trait(trait_kind) = &item.kind {
1029+
let ast::TraitKind(is_auto, unsafety, ref generics, ref generic_bounds, ref trait_items) =
1030+
**trait_kind;
10361031
let mut result = String::with_capacity(128);
10371032
let header = format!(
10381033
"{}{}{}trait ",
@@ -3119,31 +3114,35 @@ impl Rewrite for ast::ForeignItem {
31193114
let span = mk_sp(self.span.lo(), self.span.hi() - BytePos(1));
31203115

31213116
let item_str = match self.kind {
3122-
ast::ForeignItemKind::Fn(defaultness, ref fn_sig, ref generics, Some(ref body)) => {
3123-
let mut visitor = FmtVisitor::from_context(context);
3124-
visitor.block_indent = shape.indent;
3125-
visitor.last_pos = self.span.lo();
3126-
let inner_attrs = inner_attributes(&self.attrs);
3127-
let fn_ctxt = visit::FnCtxt::Foreign;
3128-
visitor.visit_fn(
3129-
visit::FnKind::Fn(fn_ctxt, self.ident, &fn_sig, &self.vis, Some(body)),
3130-
generics,
3131-
&fn_sig.decl,
3132-
self.span,
3133-
defaultness,
3134-
Some(&inner_attrs),
3135-
);
3136-
Some(visitor.buffer.to_owned())
3117+
ast::ForeignItemKind::Fn(ref fn_kind) => {
3118+
let ast::FnKind(defaultness, ref fn_sig, ref generics, ref block) = **fn_kind;
3119+
if let Some(ref body) = block {
3120+
let mut visitor = FmtVisitor::from_context(context);
3121+
visitor.block_indent = shape.indent;
3122+
visitor.last_pos = self.span.lo();
3123+
let inner_attrs = inner_attributes(&self.attrs);
3124+
let fn_ctxt = visit::FnCtxt::Foreign;
3125+
visitor.visit_fn(
3126+
visit::FnKind::Fn(fn_ctxt, self.ident, &fn_sig, &self.vis, Some(body)),
3127+
generics,
3128+
&fn_sig.decl,
3129+
self.span,
3130+
defaultness,
3131+
Some(&inner_attrs),
3132+
);
3133+
Some(visitor.buffer.to_owned())
3134+
} else {
3135+
rewrite_fn_base(
3136+
context,
3137+
shape.indent,
3138+
self.ident,
3139+
&FnSig::from_method_sig(&fn_sig, generics, self.vis.clone()),
3140+
span,
3141+
FnBraceStyle::None,
3142+
)
3143+
.map(|(s, _, _)| format!("{};", s))
3144+
}
31373145
}
3138-
ast::ForeignItemKind::Fn(_, ref fn_sig, ref generics, None) => rewrite_fn_base(
3139-
context,
3140-
shape.indent,
3141-
self.ident,
3142-
&FnSig::from_method_sig(&fn_sig, generics, self.vis.clone()),
3143-
span,
3144-
FnBraceStyle::None,
3145-
)
3146-
.map(|(s, _, _)| format!("{};", s)),
31473146
ast::ForeignItemKind::Static(ref ty, mutability, _) => {
31483147
// FIXME(#21): we're dropping potential comments in between the
31493148
// function kw here.
@@ -3158,21 +3157,20 @@ impl Rewrite for ast::ForeignItem {
31583157
// 1 = ;
31593158
rewrite_assign_rhs(context, prefix, &**ty, shape.sub_width(1)?).map(|s| s + ";")
31603159
}
3161-
ast::ForeignItemKind::TyAlias(
3162-
_,
3163-
ref generics,
3164-
ref generic_bounds,
3165-
ref type_default,
3166-
) => rewrite_type_alias(
3167-
self.ident,
3168-
type_default.as_ref(),
3169-
generics,
3170-
Some(generic_bounds),
3171-
&context,
3172-
shape.indent,
3173-
&self.vis,
3174-
self.span,
3175-
),
3160+
ast::ForeignItemKind::TyAlias(ref ty_alias_kind) => {
3161+
let ast::TyAliasKind(_, ref generics, ref generic_bounds, ref type_default) =
3162+
**ty_alias_kind;
3163+
rewrite_type_alias(
3164+
self.ident,
3165+
type_default.as_ref(),
3166+
generics,
3167+
Some(generic_bounds),
3168+
&context,
3169+
shape.indent,
3170+
&self.vis,
3171+
self.span,
3172+
)
3173+
}
31763174
ast::ForeignItemKind::MacCall(ref mac) => {
31773175
rewrite_macro(mac, None, context, shape, MacroPosition::Item)
31783176
}

0 commit comments

Comments
 (0)