suppress and compress

This commit is contained in:
csmoe 2018-05-31 17:58:48 +08:00
parent f390626778
commit 8536c288f2

View File

@ -649,8 +649,14 @@ 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);
if items.is_empty() && generics.where_clause.predicates.len() == 1 {
option.compress_where();
option.suppress_comma();
}
let mut where_clause_str = rewrite_where_clause(
context,
&generics.where_clause,
context.config.brace_style(),
@ -1380,9 +1386,9 @@ fn format_tuple_struct(
// We need to put the where clause on a new line, but we didn't
// know that earlier, so the where clause will not be indented properly.
result.push('\n');
result.push_str(
&(offset.block_only() + (context.config.tab_spaces() - 1)).to_string(context.config),
);
result
.push_str(&(offset.block_only() + (context.config.tab_spaces() - 1))
.to_string(context.config));
}
result.push_str(&where_clause_str);
@ -2133,6 +2139,14 @@ 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
}
}
fn rewrite_args(