Skip to content
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

Use the span after generics and where clause #4208

Merged
merged 1 commit into from
May 27, 2020
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
5 changes: 3 additions & 2 deletions rustfmt-core/rustfmt-lib/src/formatting/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,14 +1197,15 @@ pub(crate) fn format_trait(
}
result.push('{');

let snippet = context.snippet(item.span);
let block_span = mk_sp(generics.where_clause.span.hi(), item.span.hi());
let snippet = context.snippet(block_span);
let open_pos = snippet.find_uncommented("{")? + 1;
let outer_indent_str = offset.block_only().to_string_with_newline(context.config);

if !trait_items.is_empty() || contains_comment(&snippet[open_pos..]) {
let mut visitor = FmtVisitor::from_context(context);
visitor.block_indent = offset.block_only().block_indent(context.config);
visitor.last_pos = item.span.lo() + BytePos(open_pos as u32);
visitor.last_pos = block_span.lo() + BytePos(open_pos as u32);

for item in trait_items {
visitor.visit_trait_item(item);
Expand Down
4 changes: 4 additions & 0 deletions rustfmt-core/rustfmt-lib/tests/source/const_generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ fn foo<const X: usize>() {
}

type Foo<const N: usize> = [i32; N + 1];

pub trait Foo: Bar<{Baz::COUNT}> {
const ASD: usize;
}
4 changes: 4 additions & 0 deletions rustfmt-core/rustfmt-lib/tests/target/const_generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ fn foo<const X: usize>() {
}

type Foo<const N: usize> = [i32; N + 1];

pub trait Foo: Bar<{ Baz::COUNT }> {
const ASD: usize;
}