Skip to content

Commit ea54ac7

Browse files
committed
Seach for comment before Generics from the Trait beginning
1 parent 77c4552 commit ea54ac7

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/formatting/items.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,9 +1136,8 @@ pub(crate) fn format_trait(
11361136
);
11371137
result.push_str(&header);
11381138

1139-
// FIXME: rustfmt fails to format when there are comments between `trait` and ident.
1140-
let trait_hi = context.snippet_provider.span_after(item.span, "trait");
1141-
if contains_comment(context.snippet(mk_sp(trait_hi, generics.span.lo()))) {
1139+
// FIXME: rustfmt fails to format when there are comments before the ident.
1140+
if contains_comment(context.snippet(mk_sp(item.span.lo(), generics.span.lo()))) {
11421141
return None;
11431142
}
11441143

tests/source/lhs-to-rhs-bewteen-comments/trait.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ A + C
2727
pub trait Foo6:/* A and C */A + C + B{}
2828

2929
// Other cases
30-
trait Person {
30+
trait Person{
31+
fn name(&self) -> String;
32+
}
33+
/*comment1*/trait Person{
3134
fn name(&self) -> String;
3235
}
3336
trait Student:/* comment1 */Person/* comment2 */{

tests/target/lhs-to-rhs-bewteen-comments/trait.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ pub trait Foo6: /* A and C */ A + C + B {}
2424
trait Person {
2525
fn name(&self) -> String;
2626
}
27+
/*comment1*/
28+
trait Person {
29+
fn name(&self) -> String;
30+
}
2731
trait Student: /* comment1 */ Person /* comment2 */ {
2832
fn university(&self) -> String;
2933
}

0 commit comments

Comments
 (0)