diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2021-11-07 16:43:49 +0800 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2021-11-07 21:38:17 +0800 |
| commit | 2834f57c4584e33471f8bdc3cc57617fc0863fde (patch) | |
| tree | 5738ca3f53407100f180c11a985b1d906aa08202 /src/tools | |
| parent | 90a273b785b3bc482b82c4896ba1bdea68745e46 (diff) | |
| download | rust-2834f57c4584e33471f8bdc3cc57617fc0863fde.tar.gz rust-2834f57c4584e33471f8bdc3cc57617fc0863fde.zip | |
ast: Fix naming conventions in AST structures
TraitKind -> Trait TyAliasKind -> TyAlias ImplKind -> Impl FnKind -> Fn All `*Kind`s in AST are supposed to be enums. Tuple structs are converted to braced structs for the types above, and fields are reordered in syntactic order. Also, mutable AST visitor now correctly visit spans in defaultness, unsafety, impl polarity and constness.
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/doc.rs | 4 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/excessive_bools.rs | 12 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/non_expressive_names.rs | 6 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/write.rs | 4 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_utils/src/ast_utils.rs | 25 | ||||
| -rw-r--r-- | src/tools/rustfmt/src/items.rs | 64 | ||||
| -rw-r--r-- | src/tools/rustfmt/src/visitor.rs | 78 |
7 files changed, 115 insertions, 78 deletions
diff --git a/src/tools/clippy/clippy_lints/src/doc.rs b/src/tools/clippy/clippy_lints/src/doc.rs index 87ad5178ff0..d4ba072807f 100644 --- a/src/tools/clippy/clippy_lints/src/doc.rs +++ b/src/tools/clippy/clippy_lints/src/doc.rs @@ -5,7 +5,7 @@ use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; use clippy_utils::{is_entrypoint_fn, is_expn_of, match_panic_def_id, method_chain_args, return_ty}; use if_chain::if_chain; use itertools::Itertools; -use rustc_ast::ast::{Async, AttrKind, Attribute, FnKind, FnRetTy, ItemKind}; +use rustc_ast::ast::{Async, AttrKind, Attribute, Fn, FnRetTy, ItemKind}; use rustc_ast::token::CommentKind; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lrc; @@ -639,7 +639,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { | ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) => return false, // We found a main function ... - ItemKind::Fn(box FnKind(_, sig, _, Some(block))) if item.ident.name == sym::main => { + ItemKind::Fn(box Fn { sig, body: Some(block), .. }) if item.ident.name == sym::main => { let is_async = matches!(sig.header.asyncness, Async::Yes { .. }); let returns_nothing = match &sig.decl.output { FnRetTy::Default(..) => true, diff --git a/src/tools/clippy/clippy_lints/src/excessive_bools.rs b/src/tools/clippy/clippy_lints/src/excessive_bools.rs index 476e6d23f12..09b6e200838 100644 --- a/src/tools/clippy/clippy_lints/src/excessive_bools.rs +++ b/src/tools/clippy/clippy_lints/src/excessive_bools.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::in_macro; -use rustc_ast::ast::{AssocItemKind, Extern, FnKind, FnSig, ImplKind, Item, ItemKind, TraitKind, Ty, TyKind}; +use rustc_ast::ast::{AssocItemKind, Extern, Fn, FnSig, Impl, Item, ItemKind, Trait, Ty, TyKind}; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::{sym, Span}; @@ -162,17 +162,17 @@ impl EarlyLintPass for ExcessiveBools { ); } }, - ItemKind::Impl(box ImplKind { + ItemKind::Impl(box Impl { of_trait: None, items, .. }) - | ItemKind::Trait(box TraitKind(.., items)) => { + | ItemKind::Trait(box Trait { items, .. }) => { for item in items { - if let AssocItemKind::Fn(box FnKind(_, fn_sig, _, _)) = &item.kind { - self.check_fn_sig(cx, fn_sig, item.span); + if let AssocItemKind::Fn(box Fn { sig, .. }) = &item.kind { + self.check_fn_sig(cx, sig, item.span); } } }, - ItemKind::Fn(box FnKind(_, fn_sig, _, _)) => self.check_fn_sig(cx, fn_sig, item.span), + ItemKind::Fn(box Fn { sig, .. }) => self.check_fn_sig(cx, sig, item.span), _ => (), } } diff --git a/src/tools/clippy/clippy_lints/src/non_expressive_names.rs b/src/tools/clippy/clippy_lints/src/non_expressive_names.rs index 5b254bc8133..e28cc49bf2a 100644 --- a/src/tools/clippy/clippy_lints/src/non_expressive_names.rs +++ b/src/tools/clippy/clippy_lints/src/non_expressive_names.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; use rustc_ast::ast::{ - Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, FnKind, Item, ItemKind, Local, Pat, PatKind, + self, Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, Item, ItemKind, Local, Pat, PatKind, }; use rustc_ast::visit::{walk_block, walk_expr, walk_pat, Visitor}; use rustc_lint::{EarlyContext, EarlyLintPass}; @@ -357,7 +357,7 @@ impl EarlyLintPass for NonExpressiveNames { return; } - if let ItemKind::Fn(box FnKind(_, ref sig, _, Some(ref blk))) = item.kind { + if let ItemKind::Fn(box ast::Fn { ref sig, body: Some(ref blk), .. }) = item.kind { do_check(self, cx, &item.attrs, &sig.decl, blk); } } @@ -367,7 +367,7 @@ impl EarlyLintPass for NonExpressiveNames { return; } - if let AssocItemKind::Fn(box FnKind(_, ref sig, _, Some(ref blk))) = item.kind { + if let AssocItemKind::Fn(box ast::Fn { ref sig, body: Some(ref blk), .. }) = item.kind { do_check(self, cx, &item.attrs, &sig.decl, blk); } } diff --git a/src/tools/clippy/clippy_lints/src/write.rs b/src/tools/clippy/clippy_lints/src/write.rs index 85d1f65c51f..b412e15ae4f 100644 --- a/src/tools/clippy/clippy_lints/src/write.rs +++ b/src/tools/clippy/clippy_lints/src/write.rs @@ -4,7 +4,7 @@ use std::ops::{Deref, Range}; use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::{snippet_opt, snippet_with_applicability}; -use rustc_ast::ast::{Expr, ExprKind, ImplKind, Item, ItemKind, MacCall, Path, StrLit, StrStyle}; +use rustc_ast::ast::{Expr, ExprKind, Impl, Item, ItemKind, MacCall, Path, StrLit, StrStyle}; use rustc_ast::token::{self, LitKind}; use rustc_ast::tokenstream::TokenStream; use rustc_errors::Applicability; @@ -243,7 +243,7 @@ impl_lint_pass!(Write => [ impl EarlyLintPass for Write { fn check_item(&mut self, _: &EarlyContext<'_>, item: &Item) { - if let ItemKind::Impl(box ImplKind { + if let ItemKind::Impl(box Impl { of_trait: Some(trait_ref), .. }) = &item.kind diff --git a/src/tools/clippy/clippy_utils/src/ast_utils.rs b/src/tools/clippy/clippy_utils/src/ast_utils.rs index 2fa98831c77..1b05a8a3504 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils.rs @@ -250,7 +250,8 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { (Use(l), Use(r)) => eq_use_tree(l, r), (Static(lt, lm, le), Static(rt, rm, re)) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), (Const(ld, lt, le), Const(rd, rt, re)) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), - (Fn(box FnKind(ld, lf, lg, lb)), Fn(box FnKind(rd, rf, rg, rb))) => { + (Fn(box ast::Fn { defaultness: ld, sig: lf, generics: lg, body: lb }), + Fn(box ast::Fn { defaultness: rd, sig: rf, generics: rg, body: rb })) => { eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r)) }, (Mod(lu, lmk), Mod(ru, rmk)) => { @@ -266,7 +267,8 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { (ForeignMod(l), ForeignMod(r)) => { both(&l.abi, &r.abi, eq_str_lit) && over(&l.items, &r.items, |l, r| eq_item(l, r, eq_foreign_item_kind)) }, - (TyAlias(box TyAliasKind(ld, lg, lb, lt)), TyAlias(box TyAliasKind(rd, rg, rb, rt))) => { + (TyAlias(box ast::TyAlias { defaultness: ld, generics: lg, bounds: lb, ty: lt }), + TyAlias(box ast::TyAlias { defaultness: rd, generics: rg, bounds: rb, ty: rt })) => { eq_defaultness(*ld, *rd) && eq_generics(lg, rg) && over(lb, rb, eq_generic_bound) @@ -276,7 +278,8 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { (Struct(lv, lg), Struct(rv, rg)) | (Union(lv, lg), Union(rv, rg)) => { eq_variant_data(lv, rv) && eq_generics(lg, rg) }, - (Trait(box TraitKind(la, lu, lg, lb, li)), Trait(box TraitKind(ra, ru, rg, rb, ri))) => { + (Trait(box ast::Trait { is_auto: la, unsafety: lu, generics: lg, bounds: lb, items: li }), + Trait(box ast::Trait { is_auto: ra, unsafety: ru, generics: rg, bounds: rb, items: ri })) => { la == ra && matches!(lu, Unsafe::No) == matches!(ru, Unsafe::No) && eq_generics(lg, rg) @@ -285,7 +288,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { }, (TraitAlias(lg, lb), TraitAlias(rg, rb)) => eq_generics(lg, rg) && over(lb, rb, eq_generic_bound), ( - Impl(box ImplKind { + Impl(box ast::Impl { unsafety: lu, polarity: lp, defaultness: ld, @@ -295,7 +298,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { self_ty: lst, items: li, }), - Impl(box ImplKind { + Impl(box ast::Impl { unsafety: ru, polarity: rp, defaultness: rd, @@ -325,10 +328,12 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool { use ForeignItemKind::*; match (l, r) { (Static(lt, lm, le), Static(rt, rm, re)) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), - (Fn(box FnKind(ld, lf, lg, lb)), Fn(box FnKind(rd, rf, rg, rb))) => { + (Fn(box ast::Fn { defaultness: ld, sig: lf, generics: lg, body: lb }), + Fn(box ast::Fn { defaultness: rd, sig: rf, generics: rg, body: rb })) => { eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r)) }, - (TyAlias(box TyAliasKind(ld, lg, lb, lt)), TyAlias(box TyAliasKind(rd, rg, rb, rt))) => { + (TyAlias(box ast::TyAlias { defaultness: ld, generics: lg, bounds: lb, ty: lt }), + TyAlias(box ast::TyAlias { defaultness: rd, generics: rg, bounds: rb, ty: rt })) => { eq_defaultness(*ld, *rd) && eq_generics(lg, rg) && over(lb, rb, eq_generic_bound) @@ -343,10 +348,12 @@ pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { use AssocItemKind::*; match (l, r) { (Const(ld, lt, le), Const(rd, rt, re)) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), - (Fn(box FnKind(ld, lf, lg, lb)), Fn(box FnKind(rd, rf, rg, rb))) => { + (Fn(box ast::Fn { defaultness: ld, sig: lf, generics: lg, body: lb }), + Fn(box ast::Fn { defaultness: rd, sig: rf, generics: rg, body: rb })) => { eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r)) }, - (TyAlias(box TyAliasKind(ld, lg, lb, lt)), TyAlias(box TyAliasKind(rd, rg, rb, rt))) => { + (TyAlias(box ast::TyAlias { defaultness: ld, generics: lg, bounds: lb, ty: lt }), + TyAlias(box ast::TyAlias { defaultness: rd, generics: rg, bounds: rb, ty: rt })) => { eq_defaultness(*ld, *rd) && eq_generics(lg, rg) && over(lb, rb, eq_generic_bound) diff --git a/src/tools/rustfmt/src/items.rs b/src/tools/rustfmt/src/items.rs index 1cb1a2701c3..c828798d933 100644 --- a/src/tools/rustfmt/src/items.rs +++ b/src/tools/rustfmt/src/items.rs @@ -622,7 +622,7 @@ impl<'a> FmtVisitor<'a> { fn need_empty_line(a: &ast::AssocItemKind, b: &ast::AssocItemKind) -> bool { match (a, b) { (TyAlias(lty), TyAlias(rty)) - if both_type(<y.3, &rty.3) || both_opaque(<y.3, &rty.3) => + if both_type(<y.ty, &rty.ty) || both_opaque(<y.ty, &rty.ty) => { false } @@ -633,7 +633,7 @@ impl<'a> FmtVisitor<'a> { buffer.sort_by(|(_, a), (_, b)| match (&a.kind, &b.kind) { (TyAlias(lty), TyAlias(rty)) - if both_type(<y.3, &rty.3) || both_opaque(<y.3, &rty.3) => + if both_type(<y.ty, &rty.ty) || both_opaque(<y.ty, &rty.ty) => { a.ident.as_str().cmp(&b.ident.as_str()) } @@ -641,8 +641,8 @@ impl<'a> FmtVisitor<'a> { a.ident.as_str().cmp(&b.ident.as_str()) } (Fn(..), Fn(..)) => a.span.lo().cmp(&b.span.lo()), - (TyAlias(ty), _) if is_type(&ty.3) => Ordering::Less, - (_, TyAlias(ty)) if is_type(&ty.3) => Ordering::Greater, + (TyAlias(ty), _) if is_type(&ty.ty) => Ordering::Less, + (_, TyAlias(ty)) if is_type(&ty.ty) => Ordering::Greater, (TyAlias(..), _) => Ordering::Less, (_, TyAlias(..)) => Ordering::Greater, (Const(..), _) => Ordering::Less, @@ -679,7 +679,7 @@ pub(crate) fn format_impl( offset: Indent, ) -> Option<String> { if let ast::ItemKind::Impl(impl_kind) = &item.kind { - let ast::ImplKind { + let ast::Impl { ref generics, ref self_ty, ref items, @@ -833,7 +833,7 @@ fn format_impl_ref_and_type( offset: Indent, ) -> Option<String> { if let ast::ItemKind::Impl(impl_kind) = &item.kind { - let ast::ImplKind { + let ast::Impl { unsafety, polarity, defaultness, @@ -1029,8 +1029,13 @@ pub(crate) fn format_trait( offset: Indent, ) -> Option<String> { 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 ast::Trait { + is_auto, + unsafety, + ref generics, + ref bounds, + ref items, + } = **trait_kind; let mut result = String::with_capacity(128); let header = format!( "{}{}{}trait ", @@ -1048,11 +1053,11 @@ pub(crate) fn format_trait( result.push_str(&generics_str); // FIXME(#2055): rustfmt fails to format when there are comments between trait bounds. - if !generic_bounds.is_empty() { + if !bounds.is_empty() { let ident_hi = context .snippet_provider .span_after(item.span, &item.ident.as_str()); - let bound_hi = generic_bounds.last().unwrap().span().hi(); + let bound_hi = bounds.last().unwrap().span().hi(); let snippet = context.snippet(mk_sp(ident_hi, bound_hi)); if contains_comment(snippet) { return None; @@ -1061,7 +1066,7 @@ pub(crate) fn format_trait( result = rewrite_assign_rhs_with( context, result + ":", - generic_bounds, + bounds, shape, RhsTactics::ForceNextLineWithoutIndent, )?; @@ -1072,10 +1077,10 @@ pub(crate) fn format_trait( let where_on_new_line = context.config.indent_style() != IndentStyle::Block; let where_budget = context.budget(last_line_width(&result)); - let pos_before_where = if generic_bounds.is_empty() { + let pos_before_where = if bounds.is_empty() { generics.where_clause.span.lo() } else { - generic_bounds[generic_bounds.len() - 1].span().hi() + bounds[bounds.len() - 1].span().hi() }; let option = WhereClauseOption::snuggled(&generics_str); let where_clause_str = rewrite_where_clause( @@ -1134,7 +1139,7 @@ pub(crate) fn format_trait( BraceStyle::PreferSameLine => result.push(' '), BraceStyle::SameLineWhere => { if result.contains('\n') - || (!generics.where_clause.predicates.is_empty() && !trait_items.is_empty()) + || (!generics.where_clause.predicates.is_empty() && !items.is_empty()) { result.push_str(&offset.to_string_with_newline(context.config)); } else { @@ -1149,12 +1154,12 @@ pub(crate) fn format_trait( let open_pos = snippet.find_uncommented("{")? + 1; let outer_indent_str = offset.block_only().to_string_with_newline(context.config); - if !trait_items.is_empty() || contains_comment(&snippet[open_pos..]) { + if !items.is_empty() || contains_comment(&snippet[open_pos..]) { let mut visitor = FmtVisitor::from_context(context); visitor.block_indent = offset.block_only().block_indent(context.config); visitor.last_pos = block_span.lo() + BytePos(open_pos as u32); - for item in trait_items { + for item in items { visitor.visit_trait_item(item); } @@ -3125,17 +3130,22 @@ impl Rewrite for ast::ForeignItem { let item_str = match self.kind { 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 ast::Fn { + defaultness, + ref sig, + ref generics, + ref body, + } = **fn_kind; + if let Some(ref body) = 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)), + visit::FnKind::Fn(fn_ctxt, self.ident, &sig, &self.vis, Some(body)), generics, - &fn_sig.decl, + &sig.decl, self.span, defaultness, Some(&inner_attrs), @@ -3146,7 +3156,7 @@ impl Rewrite for ast::ForeignItem { context, shape.indent, self.ident, - &FnSig::from_method_sig(&fn_sig, generics, &self.vis), + &FnSig::from_method_sig(&sig, generics, &self.vis), span, FnBraceStyle::None, ) @@ -3168,16 +3178,20 @@ impl Rewrite for ast::ForeignItem { rewrite_assign_rhs(context, prefix, &**ty, shape.sub_width(1)?).map(|s| s + ";") } ast::ForeignItemKind::TyAlias(ref ty_alias_kind) => { - let ast::TyAliasKind(_, ref generics, ref generic_bounds, ref type_default) = - **ty_alias_kind; + let ast::TyAlias { + ref generics, + ref bounds, + ref ty, + .. + } = **ty_alias_kind; rewrite_type( &context, shape.indent, self.ident, &self.vis, generics, - Some(generic_bounds), - type_default.as_ref(), + Some(bounds), + ty.as_ref(), self.span, ) } diff --git a/src/tools/rustfmt/src/visitor.rs b/src/tools/rustfmt/src/visitor.rs index d854d90b40b..2cfd4e3f15c 100644 --- a/src/tools/rustfmt/src/visitor.rs +++ b/src/tools/rustfmt/src/visitor.rs @@ -540,24 +540,22 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { self.visit_static(&StaticParts::from_item(item)); } ast::ItemKind::Fn(ref fn_kind) => { - let ast::FnKind(defaultness, ref fn_signature, ref generics, ref block) = - **fn_kind; - if let Some(ref body) = block { + let ast::Fn { + defaultness, + ref sig, + ref generics, + ref body, + } = **fn_kind; + if let Some(ref body) = body { let inner_attrs = inner_attributes(&item.attrs); - let fn_ctxt = match fn_signature.header.ext { + let fn_ctxt = match sig.header.ext { ast::Extern::None => visit::FnCtxt::Free, _ => visit::FnCtxt::Foreign, }; self.visit_fn( - visit::FnKind::Fn( - fn_ctxt, - item.ident, - &fn_signature, - &item.vis, - Some(body), - ), + visit::FnKind::Fn(fn_ctxt, item.ident, &sig, &item.vis, Some(body)), generics, - &fn_signature.decl, + &sig.decl, item.span, defaultness, Some(&inner_attrs), @@ -565,19 +563,18 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { } else { let indent = self.block_indent; let rewrite = self.rewrite_required_fn( - indent, - item.ident, - &fn_signature, - &item.vis, - generics, - item.span, + indent, item.ident, &sig, &item.vis, generics, item.span, ); self.push_rewrite(item.span, rewrite); } } ast::ItemKind::TyAlias(ref alias_kind) => { - let ast::TyAliasKind(_, ref generics, ref generic_bounds, ref ty) = - **alias_kind; + let ast::TyAlias { + ref generics, + ref bounds, + ref ty, + .. + } = **alias_kind; match ty { Some(ty) => { let rewrite = rewrite_type( @@ -586,7 +583,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { item.ident, &item.vis, generics, - Some(generic_bounds), + Some(bounds), Some(&*ty), item.span, ); @@ -597,7 +594,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { &self.get_context(), self.block_indent, item.ident, - generic_bounds, + bounds, generics, &item.vis, item.span, @@ -639,8 +636,13 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { match ti.kind { ast::AssocItemKind::Const(..) => self.visit_static(&StaticParts::from_trait_item(ti)), ast::AssocItemKind::Fn(ref fn_kind) => { - let ast::FnKind(defaultness, ref sig, ref generics, ref block) = **fn_kind; - if let Some(ref body) = block { + let ast::Fn { + defaultness, + ref sig, + ref generics, + ref body, + } = **fn_kind; + if let Some(ref body) = body { let inner_attrs = inner_attributes(&ti.attrs); let fn_ctxt = visit::FnCtxt::Assoc(visit::AssocCtxt::Trait); self.visit_fn( @@ -659,16 +661,20 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { } } ast::AssocItemKind::TyAlias(ref ty_alias_kind) => { - let ast::TyAliasKind(_, ref generics, ref generic_bounds, ref type_default) = - **ty_alias_kind; + let ast::TyAlias { + ref generics, + ref bounds, + ref ty, + .. + } = **ty_alias_kind; let rewrite = rewrite_type( &self.get_context(), self.block_indent, ti.ident, &ti.vis, generics, - Some(generic_bounds), - type_default.as_ref(), + Some(bounds), + ty.as_ref(), ti.span, ); self.push_rewrite(ti.span, rewrite); @@ -689,8 +695,13 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { match ii.kind { ast::AssocItemKind::Fn(ref fn_kind) => { - let ast::FnKind(defaultness, ref sig, ref generics, ref block) = **fn_kind; - if let Some(ref body) = block { + let ast::Fn { + defaultness, + ref sig, + ref generics, + ref body, + } = **fn_kind; + if let Some(ref body) = body { let inner_attrs = inner_attributes(&ii.attrs); let fn_ctxt = visit::FnCtxt::Assoc(visit::AssocCtxt::Impl); self.visit_fn( @@ -710,7 +721,12 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { } ast::AssocItemKind::Const(..) => self.visit_static(&StaticParts::from_impl_item(ii)), ast::AssocItemKind::TyAlias(ref ty_alias_kind) => { - let ast::TyAliasKind(defaultness, ref generics, _, ref ty) = **ty_alias_kind; + let ast::TyAlias { + defaultness, + ref generics, + ref ty, + .. + } = **ty_alias_kind; self.push_rewrite( ii.span, rewrite_impl_type( |
