Skip to content

Commit b3cbff8

Browse files
deps: apply rustc-ap v705 changes to itemkind variants
1 parent 774ecb3 commit b3cbff8

File tree

2 files changed

+177
-161
lines changed

2 files changed

+177
-161
lines changed

Diff for: src/formatting/items.rs

+69-71
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,8 @@ impl<'a> FmtVisitor<'a> {
712712
use ast::AssocItemKind::*;
713713
fn need_empty_line(a: &ast::AssocItemKind, b: &ast::AssocItemKind) -> bool {
714714
match (a, b) {
715-
(TyAlias(_, _, _, ref lty), TyAlias(_, _, _, ref rty))
716-
if both_type(lty, rty) || both_opaque(lty, rty) =>
715+
(TyAlias(lty), TyAlias(rty))
716+
if both_type(&lty.3, &rty.3) || both_opaque(&lty.3, &rty.3) =>
717717
{
718718
false
719719
}
@@ -723,17 +723,17 @@ impl<'a> FmtVisitor<'a> {
723723
}
724724

725725
buffer.sort_by(|(_, a), (_, b)| match (&a.kind, &b.kind) {
726-
(TyAlias(_, _, _, ref lty), TyAlias(_, _, _, ref rty))
727-
if both_type(lty, rty) || both_opaque(lty, rty) =>
726+
(TyAlias(lty), TyAlias(rty))
727+
if both_type(&lty.3, &rty.3) || both_opaque(&lty.3, &rty.3) =>
728728
{
729729
compare_as_versions(&a.ident.as_str(), &b.ident.as_str())
730730
}
731731
(Const(..), Const(..)) | (MacCall(..), MacCall(..)) => {
732732
compare_as_versions(&a.ident.as_str(), &b.ident.as_str())
733733
}
734734
(Fn(..), Fn(..)) => a.span.lo().cmp(&b.span.lo()),
735-
(TyAlias(_, _, _, ref ty), _) if is_type(ty) => Ordering::Less,
736-
(_, TyAlias(_, _, _, ref ty)) if is_type(ty) => Ordering::Greater,
735+
(TyAlias(ty), _) if is_type(&ty.3) => Ordering::Less,
736+
(_, TyAlias(ty)) if is_type(&ty.3) => Ordering::Greater,
737737
(TyAlias(..), _) => Ordering::Less,
738738
(_, TyAlias(..)) => Ordering::Greater,
739739
(Const(..), _) => Ordering::Less,
@@ -769,13 +769,13 @@ pub(crate) fn format_impl(
769769
item: &ast::Item,
770770
offset: Indent,
771771
) -> Option<String> {
772-
if let ast::ItemKind::Impl {
773-
ref generics,
774-
ref self_ty,
775-
ref items,
776-
..
777-
} = item.kind
778-
{
772+
if let ast::ItemKind::Impl(impl_kind) = &item.kind {
773+
let ast::ImplKind {
774+
ref generics,
775+
ref self_ty,
776+
ref items,
777+
..
778+
} = **impl_kind;
779779
let mut result = String::with_capacity(128);
780780
let ref_and_type = format_impl_ref_and_type(context, item, offset)?;
781781
let sep = offset.to_string_with_newline(context.config);
@@ -931,17 +931,17 @@ fn format_impl_ref_and_type(
931931
item: &ast::Item,
932932
offset: Indent,
933933
) -> Option<String> {
934-
if let ast::ItemKind::Impl {
935-
unsafety,
936-
polarity,
937-
defaultness,
938-
constness,
939-
ref generics,
940-
of_trait: ref trait_ref,
941-
ref self_ty,
942-
..
943-
} = item.kind
944-
{
934+
if let ast::ItemKind::Impl(impl_kind) = &item.kind {
935+
let ast::ImplKind {
936+
unsafety,
937+
polarity,
938+
defaultness,
939+
constness,
940+
ref generics,
941+
of_trait: ref trait_ref,
942+
ref self_ty,
943+
..
944+
} = **impl_kind;
945945
let mut result = String::with_capacity(128);
946946

947947
result.push_str(&format_visibility(context, &item.vis));
@@ -1119,14 +1119,9 @@ pub(crate) fn format_trait(
11191119
item: &ast::Item,
11201120
offset: Indent,
11211121
) -> Option<String> {
1122-
if let ast::ItemKind::Trait(
1123-
is_auto,
1124-
unsafety,
1125-
ref generics,
1126-
ref generic_bounds,
1127-
ref trait_items,
1128-
) = item.kind
1129-
{
1122+
if let ast::ItemKind::Trait(trait_kind) = &item.kind {
1123+
let ast::TraitKind(is_auto, unsafety, ref generics, ref generic_bounds, ref trait_items) =
1124+
**trait_kind;
11301125
let mut result = String::with_capacity(128);
11311126
let header = format!(
11321127
"{}{}{}trait ",
@@ -3256,31 +3251,35 @@ impl Rewrite for ast::ForeignItem {
32563251
let span = mk_sp(self.span.lo(), self.span.hi() - BytePos(1));
32573252

32583253
let item_str = match self.kind {
3259-
ast::ForeignItemKind::Fn(defaultness, ref fn_sig, ref generics, Some(ref body)) => {
3260-
let mut visitor = FmtVisitor::from_context(context);
3261-
visitor.block_indent = shape.indent;
3262-
visitor.last_pos = self.span.lo();
3263-
let inner_attrs = inner_attributes(&self.attrs);
3264-
let fn_ctxt = visit::FnCtxt::Foreign;
3265-
visitor.visit_fn(
3266-
visit::FnKind::Fn(fn_ctxt, self.ident, &fn_sig, &self.vis, Some(body)),
3267-
generics,
3268-
&fn_sig.decl,
3269-
self.span,
3270-
defaultness,
3271-
Some(&inner_attrs),
3272-
);
3273-
Some(visitor.buffer.to_owned())
3254+
ast::ForeignItemKind::Fn(ref fn_kind) => {
3255+
let ast::FnKind(defaultness, ref fn_sig, ref generics, ref block) = **fn_kind;
3256+
if let Some(ref body) = block {
3257+
let mut visitor = FmtVisitor::from_context(context);
3258+
visitor.block_indent = shape.indent;
3259+
visitor.last_pos = self.span.lo();
3260+
let inner_attrs = inner_attributes(&self.attrs);
3261+
let fn_ctxt = visit::FnCtxt::Foreign;
3262+
visitor.visit_fn(
3263+
visit::FnKind::Fn(fn_ctxt, self.ident, &fn_sig, &self.vis, Some(body)),
3264+
generics,
3265+
&fn_sig.decl,
3266+
self.span,
3267+
defaultness,
3268+
Some(&inner_attrs),
3269+
);
3270+
Some(visitor.buffer.to_owned())
3271+
} else {
3272+
rewrite_fn_base(
3273+
context,
3274+
shape.indent,
3275+
self.ident,
3276+
&FnSig::from_method_sig(&fn_sig, generics, self.vis.clone()),
3277+
span,
3278+
FnBraceStyle::None,
3279+
)
3280+
.map(|(s, _, _)| format!("{};", s))
3281+
}
32743282
}
3275-
ast::ForeignItemKind::Fn(_, ref fn_sig, ref generics, None) => rewrite_fn_base(
3276-
context,
3277-
shape.indent,
3278-
self.ident,
3279-
&FnSig::from_method_sig(&fn_sig, generics, self.vis.clone()),
3280-
span,
3281-
FnBraceStyle::None,
3282-
)
3283-
.map(|(s, _, _)| format!("{};", s)),
32843283
ast::ForeignItemKind::Static(ref ty, mutability, _) => {
32853284
// FIXME(#21): we're dropping potential comments in between the
32863285
// function kw here.
@@ -3295,21 +3294,20 @@ impl Rewrite for ast::ForeignItem {
32953294
// 1 = ;
32963295
rewrite_assign_rhs(context, prefix, &**ty, shape.sub_width(1)?).map(|s| s + ";")
32973296
}
3298-
ast::ForeignItemKind::TyAlias(
3299-
_,
3300-
ref generics,
3301-
ref generic_bounds,
3302-
ref type_default,
3303-
) => rewrite_type_alias(
3304-
self.ident,
3305-
type_default.as_ref(),
3306-
generics,
3307-
Some(generic_bounds),
3308-
&context,
3309-
shape.indent,
3310-
&self.vis,
3311-
self.span,
3312-
),
3297+
ast::ForeignItemKind::TyAlias(ref ty_alias_kind) => {
3298+
let ast::TyAliasKind(_, ref generics, ref generic_bounds, ref type_default) =
3299+
**ty_alias_kind;
3300+
rewrite_type_alias(
3301+
self.ident,
3302+
type_default.as_ref(),
3303+
generics,
3304+
Some(generic_bounds),
3305+
&context,
3306+
shape.indent,
3307+
&self.vis,
3308+
self.span,
3309+
)
3310+
}
33133311
ast::ForeignItemKind::MacCall(ref mac) => {
33143312
rewrite_macro(mac, None, context, shape, MacroPosition::Item)
33153313
}

0 commit comments

Comments
 (0)