diff --git a/src/items.rs b/src/items.rs index 924c6b22969a..fe4195e174cf 100644 --- a/src/items.rs +++ b/src/items.rs @@ -963,8 +963,14 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent) .checked_sub(last_line_width(&result)) ); let pos_before_where = if type_param_bounds.is_empty() { - // We do not use this, so it does not matter - generics.span.hi + if generics.where_clause.predicates.is_empty() { + // We do not use this, so it does not matter + item.span.lo + } else { + let snippet = context.snippet(item.span); + let where_pos = snippet.find_uncommented("where"); + item.span.lo + where_pos.map_or(BytePos(0), |p| BytePos(p as u32)) + } } else { type_param_bounds[type_param_bounds.len() - 1].span().hi }; @@ -975,7 +981,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent) Shape::legacy(where_budget, offset.block_only()), where_density, "{", - !has_body, + false, trait_bound_str.is_empty() && last_line_width(&generics_str) == 1, None, item.span, diff --git a/tests/target/issue-1824.rs b/tests/target/issue-1824.rs new file mode 100644 index 000000000000..1c4c2db46dcb --- /dev/null +++ b/tests/target/issue-1824.rs @@ -0,0 +1,5 @@ +pub trait Ingredient +where + Self: Send, +{ +} diff --git a/tests/target/trait.rs b/tests/target/trait.rs index e4758e98b5e9..cb1e0beb5551 100644 --- a/tests/target/trait.rs +++ b/tests/target/trait.rs @@ -54,13 +54,13 @@ trait ConstCheck: Foo trait Tttttttttttttttttttttttttttttttttttttttttttttttttttttttttt where - T: Foo + T: Foo, { } trait Ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt where - T: Foo + T: Foo, { } @@ -75,6 +75,6 @@ trait FooBar trait WhereList where T: Foo, - J: Bar + J: Bar, { } diff --git a/tests/target/where-clause-rfc.rs b/tests/target/where-clause-rfc.rs index bdf1f9d25742..ebfdc073eaa7 100644 --- a/tests/target/where-clause-rfc.rs +++ b/tests/target/where-clause-rfc.rs @@ -110,6 +110,6 @@ pub trait SomeTrait + Display + Write + Read - + FromStr + + FromStr, { }