Skip to content
Open
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: 6 additions & 5 deletions src/formatting/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,11 +1192,12 @@ pub(crate) fn format_trait(
}
result.push_str(&where_clause_str);
}
let pre_block_span = if !generics.where_clause.predicates.is_empty() {
mk_sp(generics.where_clause.span.hi(), item.span.hi())
} else {
item.span
};
let pre_block_span =
if !generics.where_clause.predicates.is_empty() || !generics.params.is_empty() {
mk_sp(generics.where_clause.span.hi(), item.span.hi())
} else {
item.span
};
let pre_block_snippet = context.snippet(pre_block_span);
if let Some(lo) = pre_block_snippet.find('/') {
// 1 = `{`
Expand Down
22 changes: 22 additions & 0 deletions tests/source/issue-4643.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pub trait Something<
A,
// some comment
B,
C
> {
fn a(&self, x: A) -> i32;
fn b(&self, x: B) -> i32;
fn c(&self, x: C) -> i32;
}

pub trait Something<
A,
// some comment
B,
// Another comment
C
> {
fn a(&self, x: A) -> i32;
fn b(&self, x: B) -> i32;
fn c(&self, x: C) -> i32;
}
24 changes: 24 additions & 0 deletions tests/target/issue-4643.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
pub trait Something<
A,
// some comment
B,
C,
>
{
fn a(&self, x: A) -> i32;
fn b(&self, x: B) -> i32;
fn c(&self, x: C) -> i32;
}

pub trait Something<
A,
// some comment
B,
// Another comment
C,
>
{
fn a(&self, x: A) -> i32;
fn b(&self, x: B) -> i32;
fn c(&self, x: C) -> i32;
}