mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-19 03:03:21 +00:00
Add offset when rewriting index
This commit is contained in:
parent
189b6bd7bb
commit
92270ba191
12
src/expr.rs
12
src/expr.rs
@ -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);
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
7
tests/target/issue-1247.rs
Normal file
7
tests/target/issue-1247.rs
Normal 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user