Skip to content

Commit 34f9ca2

Browse files
calebcartwrightytmimi
authored andcommitted
fix: use correct span for struct generics
1 parent 5391847 commit 34f9ca2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ pub(crate) fn format_struct_struct(
12781278
let header_hi = struct_parts.ident.span.hi();
12791279
let body_lo = if let Some(generics) = struct_parts.generics {
12801280
// Adjust the span to start at the end of the generic arguments before searching for the '{'
1281-
let span = span.with_lo(generics.span.hi());
1281+
let span = span.with_lo(generics.where_clause.span.hi());
12821282
context.snippet_provider.span_after(span, "{")
12831283
} else {
12841284
context.snippet_provider.span_after(span, "{")

tests/target/issue_5691.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
struct S<const C: usize>
2+
where
3+
[(); { num_slots!(C) }]:, {
4+
/* An asterisk-based, or a double-slash-prefixed, comment here is
5+
required to trigger the fmt bug.
6+
7+
A single-line triple-slash-prefixed comment (with a field following it) is not enough - it will not trigger the fmt bug.
8+
9+
Side note: If you have a combination of two, or all three of the
10+
above mentioned types of comments here, some of them disappear
11+
after `cargo fmt`.
12+
13+
The bug gets triggered even if a field definition following the
14+
(asterisk-based, or a double-slash-prefixed) comment, too.
15+
*/
16+
}

0 commit comments

Comments
 (0)