]> git.lizzy.rs Git - rust.git/commitdiff
Correct doc comment indentation for struct fields
authorMarcus Klaas <mail@marcusklaas.nl>
Sun, 22 Nov 2015 21:55:57 +0000 (22:55 +0100)
committerMarcus Klaas <mail@marcusklaas.nl>
Sun, 22 Nov 2015 21:55:57 +0000 (22:55 +0100)
Fix https://github.com/rust-lang-nursery/rustfmt/issues/572.

src/items.rs
src/lists.rs
tests/source/structs.rs
tests/target/imports.rs
tests/target/structs.rs

index 19aec73f1165942fbdd4cc8509e24739c6f897a8..d69e186665402e3dbaf4f72566c3b49c61b13f9d 100644 (file)
@@ -1195,15 +1195,14 @@ fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Opt
             ast::StructFieldKind::NamedField(_, vis) |
             ast::StructFieldKind::UnnamedField(vis) => format_visibility(vis),
         };
-        let indent = context.block_indent.block_indent(context.config);
         let mut attr_str = try_opt!(self.node
                                         .attrs
                                         .rewrite(context,
-                                                 context.config.max_width - indent.width(),
-                                                 indent));
+                                                 context.config.max_width - offset.width(),
+                                                 offset));
         if !attr_str.is_empty() {
             attr_str.push('\n');
-            attr_str.push_str(&indent.to_string(context.config));
+            attr_str.push_str(&offset.to_string(context.config));
         }
 
         let result = match name {
index ecde4f19fe44bb3218cda74b0ac98add9cd5a0a8..5bd2845c0e51edc2641dd3c298e8339e8d3bcda3 100644 (file)
@@ -14,7 +14,6 @@
 use syntax::codemap::{self, CodeMap, BytePos};
 
 use Indent;
-use utils::wrap_str;
 use comment::{FindUncommented, rewrite_comment, find_comment_end};
 use config::Config;
 
@@ -280,12 +279,7 @@ pub fn write_list<'b, I, T>(items: I, formatting: &ListFormatting<'b>) -> Option
             }
         }
 
-        // Make sure that string actually fits.
-        let item_str = try_opt!(wrap_str(&inner_item[..],
-                                         formatting.config.max_width,
-                                         formatting.width,
-                                         formatting.indent));
-        result.push_str(&item_str);
+        result.push_str(&inner_item[..]);
 
         // Post-comments
         if tactic != DefinitiveListTactic::Vertical && item.post_comment.is_some() {
index 9a559e029db2dbbe93d24ad13ca700a4205d38dd..6d7f6213eca7a845ae9e38e58b4ab7febfe67933 100644 (file)
@@ -141,3 +141,7 @@ struct X<T> where T: Sized {
         a: T,
     }
 }
+
+struct Foo<T>(TTTTTTTTTTTTTTTTTTT,
+              /// Qux
+    UUUUUUUUUUUUUUUUUUU);
index 948b6da7c2bdc898b32e845e92268a2f803643bb..296230ef8ba8cd5af54327a06df55f37a83ab866 100644 (file)
@@ -2,7 +2,8 @@
 
 // Long import.
 use syntax::ast::{ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, ItemDefaultImpl};
-use exceedingly::looooooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ItemA, ItemB};
+use exceedingly::looooooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ItemA,
+                                                                                                ItemB};
 use exceedingly::loooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ItemA,
                                                                                              ItemB};
 
index 50090b7a5f4c17d914e620c74d8db25d98dc35e5..9e17dec1411db65fdbe524f2729163e5d7df2b7f 100644 (file)
@@ -149,3 +149,7 @@ struct X<T>
         a: T,
     }
 }
+
+struct Foo<T>(TTTTTTTTTTTTTTTTTTT,
+              /// Qux
+              UUUUUUUUUUUUUUUUUUU);