From 4d28e148a583cec7c64513ecd0dc9bd150f35f1e Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Fri, 10 Nov 2017 21:21:53 +0900 Subject: [PATCH] Return None when there are comments around trait bounds --- src/items.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/items.rs b/src/items.rs index f6a6f81dbf1e..dcca3a77cac0 100644 --- a/src/items.rs +++ b/src/items.rs @@ -942,6 +942,15 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent) 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,