]> git.lizzy.rs Git - rust.git/commitdiff
Use block indent when visual indent failed
authortopecongiro <seuchida@gmail.com>
Sun, 7 May 2017 23:07:18 +0000 (08:07 +0900)
committertopecongiro <seuchida@gmail.com>
Sun, 7 May 2017 23:07:18 +0000 (08:07 +0900)
src/expr.rs
src/visitor.rs
tests/source/large-block.rs [new file with mode: 0644]
tests/target/large-block.rs [new file with mode: 0644]

index ab831a37431323d723066c758b219a262b52cde4..5aaaa2743f867c872cf7a4205e00d7f3440edcdb 100644 (file)
@@ -681,8 +681,9 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
         };
 
         visitor.visit_block(self);
-        if visitor.failed {
-            None
+        if visitor.failed && shape.indent.alignment != 0 {
+            self.rewrite(context,
+                         Shape::indented(shape.indent.block_only(), context.config))
         } else {
             Some(format!("{}{}", prefix, visitor.buffer))
         }
index 38185047b7e0140a0500e84ad11c0ec2dfb489d2..86dd5c239cc72edc9805c650da19593cbd2e3017 100644 (file)
@@ -65,9 +65,6 @@ fn visit_stmt(&mut self, stmt: &ast::Stmt) {
                 let rewrite =
                     stmt.rewrite(&self.get_context(),
                                  Shape::indented(self.block_indent, self.config));
-                if rewrite.is_none() {
-                    self.failed = true;
-                }
                 self.push_rewrite(stmt.span, rewrite);
             }
             ast::StmtKind::Mac(ref mac) => {
@@ -433,17 +430,22 @@ pub fn visit_impl_item(&mut self, ii: &ast::ImplItem) {
 
     fn visit_mac(&mut self, mac: &ast::Mac, ident: Option<ast::Ident>, pos: MacroPosition) {
         // 1 = ;
-        let width = self.config.max_width - self.block_indent.width() - 1;
-        let rewrite = rewrite_macro(mac,
-                                    ident,
-                                    &self.get_context(),
-                                    Shape::legacy(width, self.block_indent),
-                                    pos);
+        let shape = Shape::indented(self.block_indent, self.config)
+            .sub_width(1)
+            .unwrap();
+        let rewrite = rewrite_macro(mac, ident, &self.get_context(), shape, pos);
         self.push_rewrite(mac.span, rewrite);
     }
 
     fn push_rewrite(&mut self, span: Span, rewrite: Option<String>) {
         self.format_missing_with_indent(source!(self, span).lo);
+        self.failed = match rewrite {
+            Some(ref s) if s.rewrite(&self.get_context(),
+                                     Shape::indented(self.block_indent, self.config))
+                               .is_none() => true,
+            None => true,
+            _ => self.failed,
+        };
         let result = rewrite.unwrap_or_else(|| self.snippet(span));
         self.buffer.push_str(&result);
         self.last_pos = source!(self, span).hi;
diff --git a/tests/source/large-block.rs b/tests/source/large-block.rs
new file mode 100644 (file)
index 0000000..09e9169
--- /dev/null
@@ -0,0 +1,5 @@
+fn issue1351() {
+    std_fmt_Arguments_new_v1_std_rt_begin_panic_fmt_sdfasfasdfasdf({
+        static __STATIC_FMTSTR: &'static [&'static str] = &[];
+    });
+}
diff --git a/tests/target/large-block.rs b/tests/target/large-block.rs
new file mode 100644 (file)
index 0000000..09e9169
--- /dev/null
@@ -0,0 +1,5 @@
+fn issue1351() {
+    std_fmt_Arguments_new_v1_std_rt_begin_panic_fmt_sdfasfasdfasdf({
+        static __STATIC_FMTSTR: &'static [&'static str] = &[];
+    });
+}