Add offset when rewriting index

This commit is contained in:
Seiichi Uchida 2017-05-25 23:01:41 +09:00
parent 189b6bd7bb
commit 92270ba191
4 changed files with 18 additions and 13 deletions

View File

@ -1893,13 +1893,11 @@ fn rewrite_index(expr: &ast::Expr,
("[", "]")
};
let budget = shape
.width
.checked_sub(expr_str.len() + lbr.len() + rbr.len())
.unwrap_or(0);
let index_str = index.rewrite(context, Shape::legacy(budget, shape.indent));
if let Some(index_str) = index_str {
return Some(format!("{}{}{}{}", expr_str, lbr, index_str, rbr));
let offset = expr_str.len() + lbr.len();
if let Some(index_shape) = shape.visual_indent(offset).sub_width(offset + rbr.len()) {
if let Some(index_str) = index.rewrite(context, index_shape) {
return Some(format!("{}{}{}{}", expr_str, lbr, index_str, rbr));
}
}
let indent = shape.indent.block_indent(&context.config);

View File

@ -83,9 +83,9 @@ fn floaters() {
PushParam => {
// params are 1-indexed
stack.push(mparams[match cur.to_digit(10) {
Some(d) => d as usize - 1,
None => return Err("bad param number".to_owned()),
}]
Some(d) => d as usize - 1,
None => return Err("bad param number".to_owned()),
}]
.clone());
}
}

View File

@ -82,9 +82,9 @@ fn floaters() {
PushParam => {
// params are 1-indexed
stack.push(mparams[match cur.to_digit(10) {
Some(d) => d as usize - 1,
None => return Err("bad param number".to_owned()),
}].clone());
Some(d) => d as usize - 1,
None => return Err("bad param number".to_owned()),
}].clone());
}
}
}

View File

@ -0,0 +1,7 @@
// rustfmt-max_width: 80
fn foo() {
polyfill::slice::fill(&mut self.pending[padding_pos..
(self.algorithm.block_len - 8)],
0);
}