about summary refs log tree commit diff
diff options
context:
space:
mode:
authortopecongiro <seuchida@gmail.com>2018-02-23 23:15:29 +0900
committertopecongiro <seuchida@gmail.com>2018-02-23 23:15:29 +0900
commit0d8636f229a5fd68fecc613fb5b4cefa1659f901 (patch)
treece31c2fe2888c82aae090cbabc2e1db0609810bb
parentb17c5226501aca1e7df31a3b50cca47ba080a0dc (diff)
Allow meta item's value to exceed max width
-rw-r--r--rustfmt-core/src/attr.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/rustfmt-core/src/attr.rs b/rustfmt-core/src/attr.rs
index 12ba644a2d9..5d22bd9ffe7 100644
--- a/rustfmt-core/src/attr.rs
+++ b/rustfmt-core/src/attr.rs
@@ -228,7 +228,14 @@ impl Rewrite for ast::MetaItem {
                 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)
             }
         })