]> git.lizzy.rs Git - rust.git/blobdiff - src/items.rs
Merge pull request #2138 from topecongiro/comments-around-trait-bounds
[rust.git] / src / items.rs
index dc3abd88ffd89619f2fe7ccc377eb12d63c13f03..dcca3a77cac0f2bda9cb37449f57cd9f17dd28e8 100644 (file)
@@ -937,11 +937,20 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
 
         let body_lo = context.codemap.span_after(item.span, "{");
 
-        let shape = Shape::indented(offset + last_line_width(&result), context.config);
+        let shape = Shape::indented(offset, context.config);
         let generics_str =
             rewrite_generics(context, generics, shape, mk_sp(item.span.lo(), body_lo))?;
         result.push_str(&generics_str);
 
+        // FIXME(#2055): rustfmt fails to format when there are comments between trait bounds.
+        if !type_param_bounds.is_empty() {
+            let ident_hi = context.codemap.span_after(item.span, &format!("{}", item.ident));
+            let bound_hi = type_param_bounds.last().unwrap().span().hi();
+            let snippet = context.snippet(mk_sp(ident_hi, bound_hi));
+            if contains_comment(&snippet) {
+                return None;
+            }
+        }
         let trait_bound_str = rewrite_trait_bounds(
             context,
             type_param_bounds,
@@ -1281,17 +1290,10 @@ fn format_tuple_struct(
         }
         result.push(')');
     } else {
-        // 1 = ","
-        let body = rewrite_call_inner(
-            context,
-            "",
-            &fields.iter().map(|field| field).collect::<Vec<_>>()[..],
-            span,
-            Shape::indented(offset, context.config).sub_width(1)?,
-            context.config.fn_call_width(),
-            false,
-        )?;
-        result.push_str(&body);
+        let shape = Shape::indented(offset, context.config);
+        let fields = &fields.iter().map(|field| field).collect::<Vec<_>>()[..];
+        let one_line_width = context.config.fn_call_width();
+        result = rewrite_call_inner(context, &result, fields, span, shape, one_line_width, false)?;
     }
 
     if !where_clause_str.is_empty() && !where_clause_str.contains('\n')