Skip to content

Commit

Permalink
fix(rustfmt): fix struct field formatting with doc comments present
Browse files Browse the repository at this point in the history
  • Loading branch information
tharun208 committed Feb 4, 2022
1 parent 368a9b7 commit 302a27c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,7 @@ pub(crate) fn rewrite_struct_field(
.offset_left(overhead + spacing.len())
.and_then(|ty_shape| field.ty.rewrite(context, ty_shape));
if let Some(ref ty) = orig_ty {
if !ty.contains('\n') {
if !ty.contains('\n') && !contains_comment(&attr_prefix) {
return Some(attr_prefix + &spacing + ty);
}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/source/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,13 @@ struct Test {
// #2818
struct Paren((i32)) where i32: Trait;
struct Parens((i32, i32)) where i32: Trait;

// #5215
struct MyTuple(
/// Doc Comments
/* TODO note to add more to Doc Comments */
u32,
/// Doc Comments
// TODO note
u64,
);
2 changes: 1 addition & 1 deletion tests/target/configs/struct_field_align_threshold/20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct Foo {
#[AnAttribute]
g: SomeOtherType,
/// A doc comment on a field
h: AThirdType,
h: AThirdType,
pub i: TypeForPublicField,
}

Expand Down
10 changes: 10 additions & 0 deletions tests/target/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,13 @@ where
struct Parens((i32, i32))
where
i32: Trait;

// #5215
struct MyTuple(
/// Doc Comments
// TODO note to add more to Doc Comments
u32,
/// Doc Comments
// TODO note
u64,
);

0 comments on commit 302a27c

Please sign in to comment.