Skip to content

Commit 3cae9c3

Browse files
authored
Use the span after generics and where clause (#4208)
1 parent 68fc133 commit 3cae9c3

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Diff for: rustfmt-core/rustfmt-lib/src/formatting/items.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1197,14 +1197,15 @@ pub(crate) fn format_trait(
11971197
}
11981198
result.push('{');
11991199

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

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

12091210
for item in trait_items {
12101211
visitor.visit_trait_item(item);

Diff for: rustfmt-core/rustfmt-lib/tests/source/const_generics.rs

+4
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ fn foo<const X: usize>() {
3030
}
3131

3232
type Foo<const N: usize> = [i32; N + 1];
33+
34+
pub trait Foo: Bar<{Baz::COUNT}> {
35+
const ASD: usize;
36+
}

Diff for: rustfmt-core/rustfmt-lib/tests/target/const_generics.rs

+4
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ fn foo<const X: usize>() {
2222
}
2323

2424
type Foo<const N: usize> = [i32; N + 1];
25+
26+
pub trait Foo: Bar<{ Baz::COUNT }> {
27+
const ASD: usize;
28+
}

0 commit comments

Comments
 (0)