From 7b37776ade019d8aa6cf86c5bcb2d9f39c0121a5 Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Thu, 26 Jul 2018 21:35:56 +0900 Subject: [PATCH] Modify the rule for reordering impl items 1. If two items have the same kind, then reorder them based on its ident. 2. Handle existential type. --- src/items.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/items.rs b/src/items.rs index 7da84bfe68f..8c32d393df4 100644 --- a/src/items.rs +++ b/src/items.rs @@ -591,23 +591,31 @@ impl<'a> FmtVisitor<'a> { buffer.push((self.buffer.clone(), item.clone())); self.buffer.clear(); } - // type -> const -> macro -> method + // type -> existential -> const -> macro -> method use ast::ImplItemKind::*; fn need_empty_line(a: &ast::ImplItemKind, b: &ast::ImplItemKind) -> bool { match (a, b) { - (Type(..), Type(..)) | (Const(..), Const(..)) => false, + (Type(..), Type(..)) + | (Const(..), Const(..)) + | (Existential(..), Existential(..)) => false, _ => true, } } buffer.sort_by(|(_, a), (_, b)| match (&a.node, &b.node) { + (Type(..), Type(..)) + | (Const(..), Const(..)) + | (Macro(..), Macro(..)) + | (Existential(..), Existential(..)) => a.ident.as_str().cmp(&b.ident.as_str()), + (Method(..), Method(..)) => a.span.lo().cmp(&b.span.lo()), (Type(..), _) => Ordering::Less, (_, Type(..)) => Ordering::Greater, + (Existential(..), _) => Ordering::Less, + (_, Existential(..)) => Ordering::Greater, (Const(..), _) => Ordering::Less, (_, Const(..)) => Ordering::Greater, (Macro(..), _) => Ordering::Less, (_, Macro(..)) => Ordering::Greater, - _ => a.span.lo().cmp(&b.span.lo()), }); let mut prev_kind = None; for (buf, item) in buffer {