From d13fc2289acebe8a6f52507fb53408cbac46d35f Mon Sep 17 00:00:00 2001 From: Marcus Klaas Date: Wed, 22 Jul 2015 23:39:37 +0200 Subject: [PATCH] Fix underflow bug in rewrite_call Fixes https://github.com/nrc/rustfmt/issues/148. Now properly propagates the rewrite failure instead of panicking. Added regression test from servo code. This example will be properly rewritten when https://github.com/nrc/rustfmt/issues/17 is addressed. --- src/expr.rs | 2 +- tests/target/fn.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/expr.rs b/src/expr.rs index 8dbe5c6d1dd..0beaee9dbf2 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -132,7 +132,7 @@ fn rewrite_call(context: &RewriteContext, } // 2 is for parens. - let remaining_width = width - callee_str.len() - 2; + let remaining_width = try_opt!(width.checked_sub(callee_str.len() + 2)); let offset = callee_str.len() + 1 + offset; let items = itemize_list(context.codemap, diff --git a/tests/target/fn.rs b/tests/target/fn.rs index bc05efa5351..6c41f62a8b2 100644 --- a/tests/target/fn.rs +++ b/tests/target/fn.rs @@ -79,3 +79,17 @@ fn main() { let _ = function(move || 5); let _ = move || 42; } + +fn servo() { + let constellation_chan = Constellation::::start( + compositor_proxy, + resource_task, + image_cache_task, + font_cache_task, + time_profiler_chan, + mem_profiler_chan, + devtools_chan, + storage_task, + supports_clipboard); +}