]> git.lizzy.rs Git - rust.git/commitdiff
Avoid overflow
authortopecongiro <seuchida@gmail.com>
Tue, 13 Jun 2017 15:06:48 +0000 (00:06 +0900)
committertopecongiro <seuchida@gmail.com>
Tue, 13 Jun 2017 15:06:48 +0000 (00:06 +0900)
src/items.rs
src/lib.rs

index 156528301be301ffc4683672813a9ac82260be03..5144feed4742b47ff04f58e70a454656ba43dee3 100644 (file)
@@ -1684,7 +1684,7 @@ fn rewrite_explicit_self(
                 Some(ref l) => {
                     let lifetime_str = try_opt!(l.rewrite(
                         context,
-                        Shape::legacy(usize::max_value(), Indent::empty()),
+                        Shape::legacy(context.config.max_width(), Indent::empty()),
                     ));
                     Some(format!("&{} {}self", lifetime_str, mut_str))
                 }
@@ -1697,7 +1697,7 @@ fn rewrite_explicit_self(
             let mutability = explicit_self_mutability(&args[0]);
             let type_str = try_opt!(ty.rewrite(
                 context,
-                Shape::legacy(usize::max_value(), Indent::empty()),
+                Shape::legacy(context.config.max_width(), Indent::empty()),
             ));
 
             Some(format!(
index 2aa477ccafa44a37a5ad49930224ec52f6277c0b..1775752efce409e5151b7179ee82870a1fb2965b 100644 (file)
@@ -148,8 +148,12 @@ pub fn block_indent(mut self, config: &Config) -> Indent {
     }
 
     pub fn block_unindent(mut self, config: &Config) -> Indent {
-        self.block_indent -= config.tab_spaces();
-        self
+        if self.block_indent < config.tab_spaces() {
+            Indent::new(self.block_indent, 0)
+        } else {
+            self.block_indent -= config.tab_spaces();
+            self
+        }
     }
 
     pub fn width(&self) -> usize {