Adjust non-empty tuple struct span to start before fields
Resolves 5011 Tuple structs with visibility modifiers and comments before the first field were incorrectly formatted. Comments would duplicate part of the visibility modifier and struct name. When trying to parse the tuple fields the ``items::Context`` searches for the opening '(', but because the visibility modifier introduces another '(' -- for example ``pub(crate)`` -- the parsing gets messed up. Now the span is adjusted to start after the struct identifier, or after any generics. Adjusting the span in this way ensures that the ``items::Contex`` will correctly find the tuple fields.
This commit is contained in:
parent
d41805704d
commit
f7c4a44149
@ -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,
|
||||
)?;
|
||||
|
12
tests/source/issue-5011.rs
Normal file
12
tests/source/issue-5011.rs
Normal file
@ -0,0 +1,12 @@
|
||||
pub(crate) struct ASlash(
|
||||
// hello
|
||||
i32
|
||||
);
|
||||
|
||||
pub(crate) struct AStar(
|
||||
/* hello */
|
||||
i32
|
||||
);
|
||||
|
||||
pub(crate) struct BStar(/* hello */ i32);
|
||||
|
8
tests/target/issue-5011.rs
Normal file
8
tests/target/issue-5011.rs
Normal file
@ -0,0 +1,8 @@
|
||||
pub(crate) struct ASlash(
|
||||
// hello
|
||||
i32,
|
||||
);
|
||||
|
||||
pub(crate) struct AStar(/* hello */ i32);
|
||||
|
||||
pub(crate) struct BStar(/* hello */ i32);
|
Loading…
Reference in New Issue
Block a user