Repository: rust-lang/rustfmt (rust)

Issue:
comment in const generic default causes line duplication
```rust
type Foo = impl Send;
struct Struct<
    const C: usize = {
        let _: Foo = ();
        //~^ ERROR: mismatched types
        0
    },
>;
```

gets formatted to

```rust
type Foo = impl Send;
struct Struct<
    const C: usize = {
        let _: Foo = ();
        //~^ ERROR: mismatched types
        0
    },
>
;
//~^ ERROR: mismatched types
0
},
>;
```

Without the comment, the formatting doesn't change.

Pull request description:
correct span for structs with const generics
Fixes #5668 

r? @ytmimi 

Working on doing a sync today but wanted to get this trivial fix in as part of it. Should be able to start cranking through the backlog of PRs afterwards

Patch:
diff --git a/src/items.rs b/src/items.rs
index 755a41f6..063a6428 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -1245,7 +1245,7 @@ fn format_unit_struct(
 ) -> Option<String> {
     let header_str = format_header(context, p.prefix, p.ident, p.vis, offset);
     let generics_str = if let Some(generics) = p.generics {
-        let hi = context.snippet_provider.span_before(p.span, ";");
+        let hi = context.snippet_provider.span_before_last(p.span, ";");
         format_generics(
             context,
             generics,


Test patch:
diff --git a/tests/target/issue_5668.rs b/tests/target/issue_5668.rs
new file mode 100644
index 00000000..bbd9a530
--- /dev/null
+++ b/tests/target/issue_5668.rs
@@ -0,0 +1,8 @@
+type Foo = impl Send;
+struct Struct<
+    const C: usize = {
+        let _: Foo = ();
+        //~^ ERROR: mismatched types
+        0
+    },
+>;