Skip to content

Commit 77c4552

Browse files
committed
Check for comment before Ident and related changes to tests
1 parent 9744fbd commit 77c4552

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

src/formatting/items.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,12 @@ 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()))) {
1142+
return None;
1143+
}
1144+
11391145
let body_lo = context.snippet_provider.span_after(item.span, "{");
11401146

11411147
let shape = Shape::indented(offset, context.config).offset_left(result.len())?;

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,32 @@ fn university(&self) -> String;
3636
trait Programmer/* comment1 */{
3737
fn fav_language(&self) -> String;
3838
}
39-
trait/* comment1 */CompSciStudent1:/* comment2 */Programmer + Student/* comment3 */{
39+
trait CompSciStudent1:/* comment1 */Programmer + Student/* comment2 */{
4040
fn git_username(&self) -> String;
4141
}
42-
trait/* comment1 */CompSciStudent2:/* comment2 Longggggggggggggggggggggggggggggggggggggggggggggggggg */Programmer + Student/* comment3 */{
42+
trait CompSciStudent2:/* comment1 Longggggggggggggggggggggggggggggggggggggggggggggggggg */Programmer + Student/* comment2 */{
4343
fn git_username(&self) -> String;
4444
}
45-
trait/* comment1 */CompSciStudent3:// comment2
46-
Programmer + Student/* comment3 */{
45+
trait CompSciStudent3:// comment1
46+
Programmer + Student/* comment2 */{
4747
fn git_username(&self) -> String;
4848
}
49-
trait/* comment1 */CompSciStudent4:// comment2 Longgggggggggggggggggggggggggggggggggggggggggggggggggg
50-
Programmer + Student/* comment3 */{
49+
trait CompSciStudent4:// comment1 Longgggggggggggggggggggggggggggggggggggggggggggggggggg
50+
Programmer + Student/* comment2 */{
5151
fn git_username(&self) -> String;
5252
}
53+
54+
// Comment before Ident
55+
trait /* comment1 */ Person {
56+
fn fav_language(&self) -> String;
57+
}
58+
trait // comment1
59+
Person {
60+
fn fav_language(&self) -> String;
61+
}
62+
trait /* comment 1 */ Programmer /* comment2 */ {
63+
fn fav_language(&self) -> String;
64+
}
65+
trait /* comment1 */ CompSciStudent1: /* comment2 */ Programmer + Student /* comment3 */ {
66+
fn git_username(&self) -> String;
67+
}

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,37 @@ trait Student: /* comment1 */ Person /* comment2 */ {
3030
trait Programmer /* comment1 */ {
3131
fn fav_language(&self) -> String;
3232
}
33-
trait CompSciStudent1: /* comment2 */ Programmer + Student /* comment3 */ {
33+
trait CompSciStudent1: /* comment1 */ Programmer + Student /* comment2 */ {
3434
fn git_username(&self) -> String;
3535
}
3636
trait CompSciStudent2:
37-
/* comment2 Longggggggggggggggggggggggggggggggggggggggggggggggggg */
38-
Programmer + Student /* comment3 */
37+
/* comment1 Longggggggggggggggggggggggggggggggggggggggggggggggggg */
38+
Programmer + Student /* comment2 */
3939
{
4040
fn git_username(&self) -> String;
4141
}
42-
trait CompSciStudent3: // comment2
43-
Programmer + Student /* comment3 */
42+
trait CompSciStudent3: // comment1
43+
Programmer + Student /* comment2 */
4444
{
4545
fn git_username(&self) -> String;
4646
}
47-
trait CompSciStudent4: // comment2 Longgggggggggggggggggggggggggggggggggggggggggggggggggg
48-
Programmer + Student /* comment3 */
47+
trait CompSciStudent4: // comment1 Longgggggggggggggggggggggggggggggggggggggggggggggggggg
48+
Programmer + Student /* comment2 */
4949
{
5050
fn git_username(&self) -> String;
5151
}
52+
53+
// Comment before Ident
54+
trait /* comment1 */ Person {
55+
fn fav_language(&self) -> String;
56+
}
57+
trait // comment1
58+
Person {
59+
fn fav_language(&self) -> String;
60+
}
61+
trait /* comment 1 */ Programmer /* comment2 */ {
62+
fn fav_language(&self) -> String;
63+
}
64+
trait /* comment1 */ CompSciStudent1: /* comment2 */ Programmer + Student /* comment3 */ {
65+
fn git_username(&self) -> String;
66+
}

0 commit comments

Comments
 (0)