about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/items.rs7
-rw-r--r--tests/source/issue-5011.rs12
-rw-r--r--tests/target/issue-5011.rs8
3 files changed, 26 insertions, 1 deletions
diff --git a/src/items.rs b/src/items.rs
index e8eb1c5dfbb..471a365e470 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -1469,12 +1469,17 @@ fn format_tuple_struct(
         format_empty_struct_or_tuple(context, inner_span, offset, &mut result, "(", ")");
     } else {
         let shape = Shape::indented(offset, context.config).sub_width(1)?;
+        let lo = if let Some(generics) = struct_parts.generics {
+            generics.span.hi()
+        } else {
+            struct_parts.ident.span.hi()
+        };
         result = overflow::rewrite_with_parens(
             context,
             &result,
             fields.iter(),
             shape,
-            span,
+            mk_sp(lo, span.hi()),
             context.config.fn_call_width(),
             None,
         )?;
diff --git a/tests/source/issue-5011.rs b/tests/source/issue-5011.rs
new file mode 100644
index 00000000000..b48292164e4
--- /dev/null
+++ b/tests/source/issue-5011.rs
@@ -0,0 +1,12 @@
+pub(crate) struct ASlash(
+    // hello
+    i32
+);
+
+pub(crate) struct AStar(
+    /* hello */
+    i32
+);
+
+pub(crate) struct BStar(/* hello */ i32);
+
diff --git a/tests/target/issue-5011.rs b/tests/target/issue-5011.rs
new file mode 100644
index 00000000000..9ad4a1929bd
--- /dev/null
+++ b/tests/target/issue-5011.rs
@@ -0,0 +1,8 @@
+pub(crate) struct ASlash(
+    // hello
+    i32,
+);
+
+pub(crate) struct AStar(/* hello */ i32);
+
+pub(crate) struct BStar(/* hello */ i32);