Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments around trait bounds #2138

Merged
merged 3 commits into from
Nov 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions tests/source/trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,11 @@ trait X /* comment */ {}
trait Y // comment
{
}

// #2055
pub trait Foo:
// A and C
A + C
// and B
+ B
{}
8 changes: 8 additions & 0 deletions tests/target/trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,11 @@ trait X /* comment */ {}
trait Y // comment
{
}

// #2055
pub trait Foo:
// A and C
A + C
// and B
+ B
{}