Skip to content

use correct span for struct generics #5692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ pub(crate) fn format_struct_struct(
let header_hi = struct_parts.ident.span.hi();
let body_lo = if let Some(generics) = struct_parts.generics {
// Adjust the span to start at the end of the generic arguments before searching for the '{'
let span = span.with_lo(generics.span.hi());
let span = span.with_lo(generics.where_clause.span.hi());
context.snippet_provider.span_after(span, "{")
} else {
context.snippet_provider.span_after(span, "{")
Expand Down
16 changes: 16 additions & 0 deletions tests/target/issue_5691.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
struct S<const C: usize>
where
[(); { num_slots!(C) }]:, {
/* An asterisk-based, or a double-slash-prefixed, comment here is
required to trigger the fmt bug.

A single-line triple-slash-prefixed comment (with a field following it) is not enough - it will not trigger the fmt bug.

Side note: If you have a combination of two, or all three of the
above mentioned types of comments here, some of them disappear
after `cargo fmt`.

The bug gets triggered even if a field definition following the
(asterisk-based, or a double-slash-prefixed) comment, too.
*/
}