Skip to content

compute the span after a struct-like item based on the ident description #3200

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
Nov 14, 2018
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
9 changes: 6 additions & 3 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@ impl<'a> FmtVisitor<'a> {
BracePos::Auto
},
self.block_indent,
mk_sp(span.lo(), body_start),
// make a span that starts right after `enum Foo`
mk_sp(ident.span.hi(), body_start),
last_line_width(&enum_header),
)
.unwrap();
Expand Down Expand Up @@ -1186,7 +1187,8 @@ fn format_unit_struct(context: &RewriteContext, p: &StructParts, offset: Indent)
context.config.brace_style(),
BracePos::None,
offset,
mk_sp(generics.span.lo(), hi),
// make a span that starts right after `struct Foo`
mk_sp(p.ident.span.hi(), hi),
last_line_width(&header_str),
)?
} else {
Expand All @@ -1208,7 +1210,7 @@ pub fn format_struct_struct(
let header_str = struct_parts.format_header(context);
result.push_str(&header_str);

let header_hi = span.lo() + BytePos(header_str.len() as u32);
let header_hi = struct_parts.ident.span.hi();
let body_lo = context.snippet_provider.span_after(span, "{");

let generics_str = match struct_parts.generics {
Expand All @@ -1222,6 +1224,7 @@ pub fn format_struct_struct(
BracePos::Auto
},
offset,
// make a span that starts right after `struct Foo`
mk_sp(header_hi, body_lo),
last_line_width(&result),
)?,
Expand Down
13 changes: 13 additions & 0 deletions tests/source/issue-3194.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mod m { struct S where A: B; }

mod n { struct Foo where A: B { foo: usize } }

mod o { enum Bar where A: B { Bar } }

mod with_comments {
mod m { struct S /* before where */ where A: B; /* after where */ }

mod n { struct Foo /* before where */ where A: B /* after where */ { foo: usize } }

mod o { enum Bar /* before where */ where A: B /* after where */ { Bar } }
}
52 changes: 52 additions & 0 deletions tests/target/issue-3194.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
mod m {
struct S
where
A: B;
}

mod n {
struct Foo
where
A: B,
{
foo: usize,
}
}

mod o {
enum Bar
where
A: B,
{
Bar,
}
}

mod with_comments {
mod m {
struct S
/* before where */
where
A: B; /* after where */
}

mod n {
struct Foo
/* before where */
where
A: B, /* after where */
{
foo: usize,
}
}

mod o {
enum Bar
/* before where */
where
A: B, /* after where */
{
Bar,
}
}
}