Skip to content

Commit a806883

Browse files
fix: handle param doc comments for macro scenarios
1 parent 57548aa commit a806883

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/items.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1960,14 +1960,17 @@ impl Rewrite for ast::Param {
19601960
let param_attrs_result = self
19611961
.attrs
19621962
.rewrite(context, Shape::legacy(shape.width, shape.indent))?;
1963-
let (span, has_multiple_attr_lines) = if !self.attrs.is_empty() {
1963+
// N.B. Doc comments aren't typically valid syntax, but could appear
1964+
// in the presence of certain macros - https://github.com/rust-lang/rustfmt/issues/4936
1965+
let (span, has_multiple_attr_lines, has_doc_comments) = if !self.attrs.is_empty() {
19641966
let num_attrs = self.attrs.len();
19651967
(
19661968
mk_sp(self.attrs[num_attrs - 1].span.hi(), self.pat.span.lo()),
19671969
param_attrs_result.contains('\n'),
1970+
self.attrs.iter().any(|a| a.is_doc_comment()),
19681971
)
19691972
} else {
1970-
(mk_sp(self.span.lo(), self.span.lo()), false)
1973+
(mk_sp(self.span.lo(), self.span.lo()), false, false)
19711974
};
19721975

19731976
if let Some(ref explicit_self) = self.to_self() {
@@ -1989,7 +1992,7 @@ impl Rewrite for ast::Param {
19891992
param_name,
19901993
span,
19911994
shape,
1992-
!has_multiple_attr_lines,
1995+
!has_multiple_attr_lines && !has_doc_comments,
19931996
)?;
19941997

19951998
if !is_empty_infer(&*self.ty, self.pat.span) {

tests/target/issue_4936.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#[discard_params_doc]
2+
trait Trait {
3+
fn foo(
4+
&self,
5+
/// some docs
6+
bar: String,
7+
/// another docs
8+
baz: i32,
9+
);
10+
}

0 commit comments

Comments
 (0)