]> git.lizzy.rs Git - rust.git/commitdiff
Disallow combining a method call with prefix or suffix
authortopecongiro <seuchida@gmail.com>
Tue, 22 May 2018 22:22:42 +0000 (07:22 +0900)
committertopecongiro <seuchida@gmail.com>
Tue, 22 May 2018 22:22:42 +0000 (07:22 +0900)
src/expr.rs
src/overflow.rs

index ea3ac5f58f28e61372bb879a06c632c7e95c8a02..ca2d78b03c4a56bf17aa9eeceb567a5c0d51d685 100644 (file)
@@ -2172,3 +2172,15 @@ fn can_be_overflowed(&self, _: &RewriteContext, _: usize) -> bool {
         false
     }
 }
+
+pub fn is_method_call(expr: &ast::Expr) -> bool {
+    match expr.node {
+        ast::ExprKind::MethodCall(..) => true,
+        ast::ExprKind::AddrOf(_, ref expr)
+        | ast::ExprKind::Box(ref expr)
+        | ast::ExprKind::Cast(ref expr, _)
+        | ast::ExprKind::Try(ref expr)
+        | ast::ExprKind::Unary(_, ref expr) => is_method_call(expr),
+        _ => false,
+    }
+}
index d555086cda7e4b5fd46abf51b88168ddc14fdd86..f2f05d835ff0b6eed2571a453ba6491b4a23f074 100644 (file)
@@ -18,7 +18,7 @@
 
 use closures;
 use codemap::SpanUtils;
-use expr::{is_every_expr_simple, is_nested_call, maybe_get_args_offset, ToExpr};
+use expr::{is_every_expr_simple, is_method_call, is_nested_call, maybe_get_args_offset, ToExpr};
 use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator};
 use rewrite::{Rewrite, RewriteContext};
 use shape::Shape;
@@ -231,8 +231,8 @@ fn try_overflow_last_item(&self, list_items: &mut Vec<ListItem>) -> DefinitiveLi
         let placeholder = if overflow_last {
             let old_value = *self.context.force_one_line_chain.borrow();
             if !combine_arg_with_callee {
-                if let Some(expr) = self.last_item().and_then(|item| item.to_expr()) {
-                    if let ast::ExprKind::MethodCall(..) = expr.node {
+                if let Some(ref expr) = self.last_item().and_then(|item| item.to_expr()) {
+                    if is_method_call(expr) {
                         self.context.force_one_line_chain.replace(true);
                     }
                 }