Merge pull request #2741 from csmoe/where_brace
Remove newline in empty impl
This commit is contained in:
commit
d9149fb52e
4 changed files with 38 additions and 12 deletions
34
src/items.rs
34
src/items.rs
|
|
@ -649,8 +649,20 @@ pub fn format_impl(
|
|||
} else {
|
||||
context.budget(last_line_width(&result))
|
||||
};
|
||||
let option = WhereClauseOption::snuggled(&ref_and_type);
|
||||
let where_clause_str = rewrite_where_clause(
|
||||
|
||||
let mut option = WhereClauseOption::snuggled(&ref_and_type);
|
||||
let snippet = context.snippet(item.span);
|
||||
let open_pos = snippet.find_uncommented("{")? + 1;
|
||||
if !contains_comment(&snippet[open_pos..])
|
||||
&& items.is_empty()
|
||||
&& generics.where_clause.predicates.len() == 1
|
||||
{
|
||||
option.suppress_comma();
|
||||
option.snuggle();
|
||||
option.compress_where();
|
||||
}
|
||||
|
||||
let mut where_clause_str = rewrite_where_clause(
|
||||
context,
|
||||
&generics.where_clause,
|
||||
context.config.brace_style(),
|
||||
|
|
@ -684,6 +696,12 @@ pub fn format_impl(
|
|||
if is_impl_single_line(context, items, &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 generics.where_clause.predicates.len() == 1 {
|
||||
result.push_str(",");
|
||||
}
|
||||
result.push_str(&format!("{}{{{}}}", &sep, &sep));
|
||||
} else {
|
||||
result.push_str(" {}");
|
||||
|
|
@ -2133,6 +2151,18 @@ impl WhereClauseOption {
|
|||
compress_where: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn suppress_comma(&mut self) {
|
||||
self.suppress_comma = true
|
||||
}
|
||||
|
||||
pub fn compress_where(&mut self) {
|
||||
self.compress_where = true
|
||||
}
|
||||
|
||||
pub fn snuggle(&mut self) {
|
||||
self.snuggle = true
|
||||
}
|
||||
}
|
||||
|
||||
fn rewrite_args(
|
||||
|
|
|
|||
|
|
@ -22,3 +22,5 @@ where
|
|||
fn lorem<Ipsum, Dolor, Sit, Amet>() -> T where Ipsum: Eq {
|
||||
// body
|
||||
}
|
||||
|
||||
unsafe impl Sync for Foo where (): Send {}
|
||||
|
|
|
|||
|
|
@ -26,3 +26,5 @@ fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
|
|||
where Ipsum: Eq {
|
||||
// body
|
||||
}
|
||||
|
||||
unsafe impl Sync for Foo where (): Send {}
|
||||
|
|
|
|||
|
|
@ -48,11 +48,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Foo for Bar<T>
|
||||
where
|
||||
T: Baz,
|
||||
{
|
||||
}
|
||||
impl<T> Foo for Bar<T> where T: Baz {}
|
||||
|
||||
impl<T> Foo for Bar<T>
|
||||
where
|
||||
|
|
@ -133,11 +129,7 @@ mod m {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> PartialEq for S<T>
|
||||
where
|
||||
T: PartialEq,
|
||||
{
|
||||
}
|
||||
impl<T> PartialEq for S<T> where T: PartialEq {}
|
||||
}
|
||||
|
||||
impl<BorrowType, K, V, NodeType, HandleType>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue