Repository: rust-lang/rustfmt (2026-03-24T07:11:12Z)

Issue:
Commented function parameter causes wrapping which breaks function declaration
## Summary

I tried to format this code:

```rust
pub async fn foo(
    // OriginalUri(original_uri): OriginalUri,
) -> Option<Option<Option<Option<String>>>> {
    None
}
```

### Expected behavior

I expected the code to continue to successfully compile after `rustfmt`.

### Actual behavior

It gets reformatted to:

```rust
pub async fn foo(// OriginalUri(original_uri): OriginalUri,)
 -> Option<Option<Option<Option<String>>>> {
    None
}
```

where the closing `)` ends up being commented out.

This only happens if both the comment and the return type are sufficiently long/complex.

## Configuration

```bash
$ rustfmt +nightly --edition 2024 src/lib.rs
```

## Meta
<!--
If you're using the stable version of rustfmt, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustfmt --version`:
```
rustfmt 1.9.0-nightly (0c68443b0a 2026-03-10)
```


<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_ASSIGN_START -->

<!-- TRIAGEBOT_ASSIGN_END -->
<!-- TRIAGEBOT_END -->


Discussion:
Triage: doesn't need nightly, just need to specify edition.

```
$ rustfmt repro.rs --check --edition=2024
```

```
rustfmt 1.8.0-stable (4a4ef493e3 2026-03-02)
```
Very similar to https://github.com/rust-lang/rustfmt/issues/6520, but I don't think this is a straight duplicate since the function parameters are empty in this example.
@rustbot claim



Patch:
diff --git a/src/items.rs b/src/items.rs
index 775c763e0bd..a2c0e8e0f50 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -2586,13 +2586,13 @@ fn rewrite_fn_base(
             .map_or(false, |last_line| last_line.contains("//"));
 
         if context.config.style_edition() >= StyleEdition::Edition2024 {
-            if closing_paren_overflow_max_width {
-                result.push(')');
+            if params_last_line_contains_comment {
                 result.push_str(&indent.to_string_with_newline(context.config));
+                result.push(')');
                 no_params_and_over_max_width = true;
-            } else if params_last_line_contains_comment {
-                result.push_str(&indent.to_string_with_newline(context.config));
+            } else if closing_paren_overflow_max_width {
                 result.push(')');
+                result.push_str(&indent.to_string_with_newline(context.config));
                 no_params_and_over_max_width = true;
             } else {
                 result.push(')');


Test patch:
diff --git a/tests/source/issue-6825.rs b/tests/source/issue-6825.rs
new file mode 100644
index 00000000000..67677f14fdb
--- /dev/null
+++ b/tests/source/issue-6825.rs
@@ -0,0 +1,7 @@
+// rustfmt-edition: 2024
+// rustfmt-style_edition: 2024
+pub async fn foo(
+    // OriginalUri(original_uri): OriginalUri,
+) -> Option<Option<Option<Option<String>>>> {
+    None
+}
diff --git a/tests/target/issue-6825.rs b/tests/target/issue-6825.rs
new file mode 100644
index 00000000000..6c9ac60dddb
--- /dev/null
+++ b/tests/target/issue-6825.rs
@@ -0,0 +1,6 @@
+// rustfmt-edition: 2024
+// rustfmt-style_edition: 2024
+pub async fn foo(// OriginalUri(original_uri): OriginalUri,
+) -> Option<Option<Option<Option<String>>>> {
+    None
+}