Search for struct body span after any generic arguments
Fixes 5273
Previously, rustfmt searched for the start of a struct body after the
opening `{`. In most cases this works just fine, but const values can
also be defined between `{ }`, which lead to issues when rewriting the
struct body.
Now, rustfmt will search for the `{` after the generic argument list to
guarantee that the `{` it finds is the start of the struct body.
This commit is contained in:
parent
a36dc368d7
commit
e41329ce87
2 changed files with 10 additions and 1 deletions
|
|
@ -1273,7 +1273,13 @@ pub(crate) fn format_struct_struct(
|
|||
result.push_str(&header_str);
|
||||
|
||||
let header_hi = struct_parts.ident.span.hi();
|
||||
let body_lo = context.snippet_provider.span_after(span, "{");
|
||||
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());
|
||||
context.snippet_provider.span_after(span, "{")
|
||||
} else {
|
||||
context.snippet_provider.span_after(span, "{")
|
||||
};
|
||||
|
||||
let generics_str = match struct_parts.generics {
|
||||
Some(g) => format_generics(
|
||||
|
|
|
|||
3
tests/target/issue_5273.rs
Normal file
3
tests/target/issue_5273.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
struct Example<const N: usize = { 1048576 }> {
|
||||
//
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue