diff options
| author | Nick Cameron <nrc@ncameron.org> | 2017-05-26 08:43:52 +1200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-26 08:43:52 +1200 |
| commit | 3d135ebba473afd378fd08d25e9caad8deaea8d3 (patch) | |
| tree | 820124e6a4f84ed000d498147c283e1b14bb06c8 /src/expr.rs | |
| parent | 662811b3f0a4187f1a27eaa9880581329f256d85 (diff) | |
| parent | 92270ba191e53fa3d9a5dbdc8cc36b5f8749cbd7 (diff) | |
Merge pull request #1586 from topecongiro/minor
Fix minor bugs
Diffstat (limited to 'src/expr.rs')
| -rw-r--r-- | src/expr.rs | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/expr.rs b/src/expr.rs index 4a415a5cc82..318ec8e59b5 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1887,13 +1887,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); |
