Fix offset for unary operations

Fixes https://github.com/nrc/rustfmt/issues/227.
This commit is contained in:
Marcus Klaas 2015-08-31 19:15:40 +02:00
parent 2bf4d74832
commit a896d91ff6
3 changed files with 16 additions and 4 deletions

View file

@ -1134,11 +1134,10 @@ fn rewrite_unary_op(context: &RewriteContext,
ast::UnOp::UnNot => "!",
ast::UnOp::UnNeg => "-",
};
let operator_len = operator_str.len();
let subexpr =
try_opt!(expr.rewrite(context, try_opt!(width.checked_sub(operator_str.len())), offset));
Some(format!("{}{}", operator_str, subexpr))
expr.rewrite(context, try_opt!(width.checked_sub(operator_len)), offset + operator_len)
.map(|r| format!("{}{}", operator_str, r))
}
fn rewrite_assignment(context: &RewriteContext,

View file

@ -105,3 +105,9 @@ fn qux() {
// A block with a comment.
}
}
fn issue227() {
{
let handler = box DocumentProgressHandler::new(addr, DocumentProgressTask::DOMContentLoaded);
}
}

View file

@ -139,3 +139,10 @@ fn qux() {
// A block with a comment.
}
}
fn issue227() {
{
let handler = box DocumentProgressHandler::new(addr,
DocumentProgressTask::DOMContentLoaded);
}
}