.collect::<Option<Vec<_>>>());
// Total of all items excluding the last.
- let almost_total = rewrites.split_last()
- .unwrap()
- .1
- .iter()
- .fold(0, |a, b| a + first_line_width(b)) +
+ let almost_total = rewrites[..rewrites.len() - 1]
+ .iter()
+ .fold(0, |a, b| a + first_line_width(b)) +
parent_rewrite.len();
let total_width = almost_total + first_line_width(rewrites.last().unwrap());
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
};
match subexpr_list[0].node {
ast::Expr_::ExprMethodCall(ref method_name, ref types, ref expressions)
if context.config.chains_overflow_last => {
- let (last, init) = rewrites.split_last_mut().unwrap();
+ let len = rewrites.len();
+ let (init, last) = rewrites.split_at_mut(len - 1);
+ let last = &mut last[0];
if init.iter().all(|s| !s.contains('\n')) && total_width <= width {
let last_rewrite = width.checked_sub(almost_total)