Skip to content

Commit da30d23

Browse files
authored
Merge pull request #2771 from topecongiro/issue-2746
Fix poor formatting of impls
2 parents 576e9af + d96d853 commit da30d23

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

src/items.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ pub fn format_impl(
656656
if !contains_comment(&snippet[open_pos..])
657657
&& items.is_empty()
658658
&& generics.where_clause.predicates.len() == 1
659+
&& !result.contains('\n')
659660
{
660661
option.suppress_comma();
661662
option.snuggle();
@@ -709,11 +710,6 @@ pub fn format_impl(
709710
return Some(result);
710711
}
711712

712-
if !where_clause_str.is_empty() && !where_clause_str.contains('\n') {
713-
let width = offset.block_indent + context.config.tab_spaces() - 1;
714-
let where_indent = Indent::new(0, width);
715-
result.push_str(&where_indent.to_string_with_newline(context.config));
716-
}
717713
result.push_str(&where_clause_str);
718714

719715
let need_newline = last_line_contains_single_line_comment(&result) || result.contains('\n');
@@ -754,7 +750,7 @@ pub fn format_impl(
754750
result.push_str(&outer_indent_str);
755751
}
756752

757-
if result.ends_with('{') {
753+
if result.ends_with('{') && !context.config.empty_item_single_line() {
758754
result.push_str(&sep);
759755
}
760756
result.push('}');
@@ -2147,7 +2143,7 @@ impl WhereClauseOption {
21472143
pub fn snuggled(current: &str) -> WhereClauseOption {
21482144
WhereClauseOption {
21492145
suppress_comma: false,
2150-
snuggle: trimmed_last_line_width(current) == 1,
2146+
snuggle: last_line_width(current) == 1,
21512147
compress_where: false,
21522148
}
21532149
}

tests/source/impls.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,6 @@ impl Foo {
157157
impl<'a, 'b, 'c> SomeThing<Something> for (&'a mut SomethingLong, &'b mut SomethingLong, &'c mut SomethingLong) {
158158
fn foo() {}
159159
}
160+
161+
// #2746
162+
impl<'seq1, 'seq2, 'body, 'scope, Channel> Adc12< Dual, MasterRunningDma<'seq1, 'body, 'scope, Channel>, SlaveRunningDma<'seq2, 'body, 'scope>, > where Channel: DmaChannel, {}

tests/target/big-impl-block.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,4 @@ where
8080
S: event::Stream,
8181
F: for<'t> FnMut(transform::Api<'t, Stream<ContentStream<S>>>) -> transform::Api<'t, X>,
8282
X: event::Stream,
83-
{
84-
}
83+
{}

tests/target/impls.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,11 @@ mod m {
134134

135135
impl<BorrowType, K, V, NodeType, HandleType>
136136
Handle<NodeRef<BorrowType, K, V, NodeType>, HandleType>
137-
{
138-
}
137+
{}
139138

140139
impl<BorrowType, K, V, NodeType, HandleType> PartialEq
141140
for Handle<NodeRef<BorrowType, K, V, NodeType>, HandleType>
142-
{
143-
}
141+
{}
144142

145143
mod x {
146144
impl<A, B, C, D> Foo
@@ -149,8 +147,7 @@ mod x {
149147
B: 'static,
150148
C: 'static,
151149
D: 'static,
152-
{
153-
}
150+
{}
154151
}
155152

156153
impl<ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNodeFoo>
@@ -222,3 +219,14 @@ impl<'a, 'b, 'c> SomeThing<Something>
222219
{
223220
fn foo() {}
224221
}
222+
223+
// #2746
224+
impl<'seq1, 'seq2, 'body, 'scope, Channel>
225+
Adc12<
226+
Dual,
227+
MasterRunningDma<'seq1, 'body, 'scope, Channel>,
228+
SlaveRunningDma<'seq2, 'body, 'scope>,
229+
>
230+
where
231+
Channel: DmaChannel,
232+
{}

0 commit comments

Comments
 (0)