Skip to content

Commit 302a27c

Browse files
committed
fix(rustfmt): fix struct field formatting with doc comments present
Fixes rust-lang#5215
1 parent 368a9b7 commit 302a27c

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

Diff for: src/items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,7 @@ pub(crate) fn rewrite_struct_field(
17331733
.offset_left(overhead + spacing.len())
17341734
.and_then(|ty_shape| field.ty.rewrite(context, ty_shape));
17351735
if let Some(ref ty) = orig_ty {
1736-
if !ty.contains('\n') {
1736+
if !ty.contains('\n') && !contains_comment(&attr_prefix) {
17371737
return Some(attr_prefix + &spacing + ty);
17381738
}
17391739
}

Diff for: tests/source/structs.rs

+10
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,13 @@ struct Test {
296296
// #2818
297297
struct Paren((i32)) where i32: Trait;
298298
struct Parens((i32, i32)) where i32: Trait;
299+
300+
// #5215
301+
struct MyTuple(
302+
/// Doc Comments
303+
/* TODO note to add more to Doc Comments */
304+
u32,
305+
/// Doc Comments
306+
// TODO note
307+
u64,
308+
);

Diff for: tests/target/configs/struct_field_align_threshold/20.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub struct Foo {
4343
#[AnAttribute]
4444
g: SomeOtherType,
4545
/// A doc comment on a field
46-
h: AThirdType,
46+
h: AThirdType,
4747
pub i: TypeForPublicField,
4848
}
4949

Diff for: tests/target/structs.rs

+10
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,13 @@ where
356356
struct Parens((i32, i32))
357357
where
358358
i32: Trait;
359+
360+
// #5215
361+
struct MyTuple(
362+
/// Doc Comments
363+
// TODO note to add more to Doc Comments
364+
u32,
365+
/// Doc Comments
366+
// TODO note
367+
u64,
368+
);

0 commit comments

Comments
 (0)