Repository: rust-lang/rustfmt (rust)

Issue:
Fn params are commented out with doc comments.
```text
$ git rev-parse HEAD
3d8cd57c2f166cb92204e95a5f4c73ab20fed4f2

$ cat example.rs
#[discard_params_doc]
trait Trait {
    fn foo(
        &self,
        /// some docs
        bar: String,
        /// another docs
        baz: i32,
    );
}

$ cargo run --bin rustfmt -- --edition=2018 < example.rs 2> /dev/null
#[discard_params_doc]
trait Trait {
    fn foo(&self, /// some docs bar: String, /// another docs baz: i32
    );
}
```

Normally doc comments on fn params triggers compile error. But it's ok if attribute macro discards it anyway... unless I run rustfmt on it.

Pull request description:
handle param doc comments for macro scenarios
Fixes #4936 

Patch:
diff --git a/src/items.rs b/src/items.rs
index 6ba83b57..e8eb1c5d 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -1960,14 +1960,17 @@ impl Rewrite for ast::Param {
         let param_attrs_result = self
             .attrs
             .rewrite(context, Shape::legacy(shape.width, shape.indent))?;
-        let (span, has_multiple_attr_lines) = if !self.attrs.is_empty() {
+        // N.B. Doc comments aren't typically valid syntax, but could appear
+        // in the presence of certain macros - https://github.com/rust-lang/rustfmt/issues/4936
+        let (span, has_multiple_attr_lines, has_doc_comments) = if !self.attrs.is_empty() {
             let num_attrs = self.attrs.len();
             (
                 mk_sp(self.attrs[num_attrs - 1].span.hi(), self.pat.span.lo()),
                 param_attrs_result.contains('\n'),
+                self.attrs.iter().any(|a| a.is_doc_comment()),
             )
         } else {
-            (mk_sp(self.span.lo(), self.span.lo()), false)
+            (mk_sp(self.span.lo(), self.span.lo()), false, false)
         };
 
         if let Some(ref explicit_self) = self.to_self() {
@@ -1989,7 +1992,7 @@ impl Rewrite for ast::Param {
                 param_name,
                 span,
                 shape,
-                !has_multiple_attr_lines,
+                !has_multiple_attr_lines && !has_doc_comments,
             )?;
 
             if !is_empty_infer(&*self.ty, self.pat.span) {


Test patch:
diff --git a/tests/target/issue_4936.rs b/tests/target/issue_4936.rs
new file mode 100644
index 00000000..c19e505f
--- /dev/null
+++ b/tests/target/issue_4936.rs
@@ -0,0 +1,10 @@
+#[discard_params_doc]
+trait Trait {
+    fn foo(
+        &self,
+        /// some docs
+        bar: String,
+        /// another docs
+        baz: i32,
+    );
+}