Fixes comma added to comment in where-clause

This commit is contained in:
GambitingMan 2023-11-01 18:00:38 +01:00 committed by Caleb Cartwright
parent 041f113159
commit 8d2c4157e6
2 changed files with 11 additions and 4 deletions

View File

@ -831,13 +831,15 @@ pub(crate) fn format_impl(
if is_impl_single_line(context, items.as_slice(), &result, &where_clause_str, item)? {
result.push_str(&where_clause_str);
if where_clause_str.contains('\n') || last_line_contains_single_line_comment(&result) {
// if the where_clause contains extra comments AND
// there is only one where-clause predicate
// recover the suppressed comma in single line where_clause formatting
if where_clause_str.contains('\n') {
// If there is only one where-clause predicate
// and the where-clause spans multiple lines,
// then recover the suppressed comma in single line where-clause formatting
if generics.where_clause.predicates.len() == 1 {
result.push(',');
}
}
if where_clause_str.contains('\n') || last_line_contains_single_line_comment(&result) {
result.push_str(&format!("{sep}{{{sep}}}"));
} else {
result.push_str(" {}");

View File

@ -32,6 +32,11 @@ impl<T> Foo for T
{
}
// #5941
impl T where (): Clone // Should not add comma to comment
{
}
// #1823
default impl Trait for X {}
default unsafe impl Trait for Y {}