Skip to content

Commit fbcc886

Browse files
committed
Disallow combining a method call with prefix or suffix
1 parent d098065 commit fbcc886

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/expr.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,3 +2172,15 @@ impl ToExpr for ast::GenericParam {
21722172
false
21732173
}
21742174
}
2175+
2176+
pub fn is_method_call(expr: &ast::Expr) -> bool {
2177+
match expr.node {
2178+
ast::ExprKind::MethodCall(..) => true,
2179+
ast::ExprKind::AddrOf(_, ref expr)
2180+
| ast::ExprKind::Box(ref expr)
2181+
| ast::ExprKind::Cast(ref expr, _)
2182+
| ast::ExprKind::Try(ref expr)
2183+
| ast::ExprKind::Unary(_, ref expr) => is_method_call(expr),
2184+
_ => false,
2185+
}
2186+
}

src/overflow.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use syntax::parse::token::DelimToken;
1818

1919
use closures;
2020
use codemap::SpanUtils;
21-
use expr::{is_every_expr_simple, is_nested_call, maybe_get_args_offset, ToExpr};
21+
use expr::{is_every_expr_simple, is_method_call, is_nested_call, maybe_get_args_offset, ToExpr};
2222
use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator};
2323
use rewrite::{Rewrite, RewriteContext};
2424
use shape::Shape;
@@ -231,8 +231,8 @@ impl<'a, T: 'a + Rewrite + ToExpr + Spanned> Context<'a, T> {
231231
let placeholder = if overflow_last {
232232
let old_value = *self.context.force_one_line_chain.borrow();
233233
if !combine_arg_with_callee {
234-
if let Some(expr) = self.last_item().and_then(|item| item.to_expr()) {
235-
if let ast::ExprKind::MethodCall(..) = expr.node {
234+
if let Some(ref expr) = self.last_item().and_then(|item| item.to_expr()) {
235+
if is_method_call(expr) {
236236
self.context.force_one_line_chain.replace(true);
237237
}
238238
}

0 commit comments

Comments
 (0)