]> git.lizzy.rs Git - rust.git/commitdiff
Fix overlong impl (#1091)
authordawirstejeck <dawirstejeck@users.noreply.github.com>
Tue, 26 Jul 2016 05:34:11 +0000 (07:34 +0200)
committerNick Cameron <nrc@ncameron.org>
Tue, 26 Jul 2016 05:34:11 +0000 (17:34 +1200)
* Fix issue-1048

* Take possible where-clause into account

* Move test to existing test set

* Fix wrong variable name

src/items.rs
tests/source/impls.rs
tests/target/impls.rs

index 1de56220cf4346740966b1c3820616188346edef..a0e5626b8829c6f0f41db01b0006e0bab2f4d972 100644 (file)
@@ -440,6 +440,7 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) -
                                ref self_ty,
                                ref items) = item.node {
         let mut result = String::new();
+
         result.push_str(&*format_visibility(&item.vis));
         result.push_str(format_unsafety(unsafety));
         result.push_str("impl");
@@ -470,7 +471,18 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) -
             result.push_str(" for ");
         }
 
-        let budget = try_opt!(context.config.max_width.checked_sub(result.len()));
+        let mut used_space = result.len();
+        if generics.where_clause.predicates.is_empty() {
+            // If there is no where clause adapt budget for type formatting to take space and curly
+            // brace into account.
+            match context.config.item_brace_style {
+                BraceStyle::AlwaysNextLine => {}
+                BraceStyle::PreferSameLine => used_space += 2,
+                BraceStyle::SameLineWhere => used_space += 2,
+            }
+        }
+
+        let budget = try_opt!(context.config.max_width.checked_sub(used_space));
         let indent = offset + result.len();
         result.push_str(&*try_opt!(self_ty.rewrite(context, budget, indent)));
 
index 0eb084018bc9ec991e5950d4ece4a4cda23cf293..5fbcecb970086564e839e707251785bf33410bff 100644 (file)
@@ -97,3 +97,6 @@ fn eq(&self, other: &Self) {
 
         impl<T> PartialEq for S<T> where T: PartialEq {      }
  }
+
+impl<BorrowType, K, V, NodeType, HandleType> Handle<NodeRef<BorrowType, K, V, NodeType>, HandleType> {
+}
index 38c972c003181f80dbb43c89ca4593be43882b54..03045c21ac59573c4d70a002024f638433be9998 100644 (file)
@@ -124,3 +124,7 @@ fn eq(&self, other: &Self) {
 
     impl<T> PartialEq for S<T> where T: PartialEq {}
 }
+
+impl<BorrowType, K, V, NodeType, HandleType> Handle<NodeRef<BorrowType, K, V, NodeType>,
+                                                    HandleType> {
+}