]> git.lizzy.rs Git - rust.git/commitdiff
Allow meta item's value to exceed max width
authortopecongiro <seuchida@gmail.com>
Fri, 23 Feb 2018 14:15:29 +0000 (23:15 +0900)
committertopecongiro <seuchida@gmail.com>
Fri, 23 Feb 2018 14:15:29 +0000 (23:15 +0900)
rustfmt-core/src/attr.rs

index 12ba644a2d9fdfe5d9b741c963429b7d3606fa74..5d22bd9ffe7fa87d8f33279522d8f873f0416e31 100644 (file)
@@ -228,7 +228,14 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
                 let name = self.name.as_str();
                 // 3 = ` = `
                 let lit_shape = shape.shrink_left(name.len() + 3)?;
-                let value = rewrite_literal(context, literal, lit_shape)?;
+                // `rewrite_literal` returns `None` when `literal` exceeds max
+                // width. Since a literal is basically unformattable unless it
+                // is a string literal (and only if `format_strings` is set),
+                // we might be better off ignoring the fact that the attribute
+                // is longer than the max width and contiue on formatting.
+                // See #2479 for example.
+                let value = rewrite_literal(context, literal, lit_shape)
+                    .unwrap_or_else(|| context.snippet(literal.span).to_owned());
                 format!("{} = {}", name, value)
             }
         })