diff options
| author | Nick Cameron <nrc@ncameron.org> | 2015-10-24 11:14:24 +1300 |
|---|---|---|
| committer | Nick Cameron <nrc@ncameron.org> | 2015-10-24 11:14:24 +1300 |
| commit | 45bcf59bdee49bb81182e89abceae2d5466e9986 (patch) | |
| tree | 510aa2655b3ebf20986c95dfe42e5ea6b723f194 /src/chains.rs | |
| parent | 02c118ae7207c2d5a48a2b1cf5f6a59dbbe1d314 (diff) | |
| parent | 0bb979bb852ca8889492f595245ec9f55d1c94e8 (diff) | |
Merge pull request #528 from marcusklaas/chain-idempotence
Restore idempotence for chain formatting
Diffstat (limited to 'src/chains.rs')
| -rw-r--r-- | src/chains.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/chains.rs b/src/chains.rs index 4716f545b3f..f004a5798c2 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -80,11 +80,11 @@ pub fn rewrite_chain(mut expr: &ast::Expr, let veto_single_line = if context.config.take_source_hints && subexpr_list.len() > 1 { // Look at the source code. Unless all chain elements start on the same // line, we won't consider putting them on a single line either. - let first_line_no = context.codemap.lookup_char_pos(subexpr_list[0].span.lo).line; + let last_span = context.snippet(mk_sp(subexpr_list[1].span.hi, total_span.hi)); + let first_span = context.snippet(subexpr_list[1].span); + let last_iter = last_span.chars().take_while(|c| c.is_whitespace()); - subexpr_list[1..] - .iter() - .any(|ex| context.codemap.lookup_char_pos(ex.span.hi).line != first_line_no) + first_span.chars().chain(last_iter).any(|c| c == '\n') } else { false }; |
