about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSeiichi Uchida <seuchida@gmail.com>2020-05-27 12:31:14 +0900
committerCaleb Cartwright <calebcartwright@users.noreply.github.com>2021-01-27 18:50:03 -0600
commitc0fede355cf274cb6d71e1f870f752f30e0f23cd (patch)
tree7629832874f040cf1edb203606941eff0817618c
parent269584634a7657d1026cee2db1c38d75cebbbd31 (diff)
downloadrust-c0fede355cf274cb6d71e1f870f752f30e0f23cd.tar.gz
rust-c0fede355cf274cb6d71e1f870f752f30e0f23cd.zip
Use the span after generics and where clause (#4208)
-rw-r--r--src/items.rs5
-rw-r--r--tests/source/const_generics.rs4
-rw-r--r--tests/target/const_generics.rs4
3 files changed, 11 insertions, 2 deletions
diff --git a/src/items.rs b/src/items.rs
index b5e38c58267..70cd7faad8b 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -1141,14 +1141,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);
diff --git a/tests/source/const_generics.rs b/tests/source/const_generics.rs
index 420810b92ea..07ef99107a8 100644
--- a/tests/source/const_generics.rs
+++ b/tests/source/const_generics.rs
@@ -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;
+}
diff --git a/tests/target/const_generics.rs b/tests/target/const_generics.rs
index f60b7eb0880..f49c5a1bb10 100644
--- a/tests/target/const_generics.rs
+++ b/tests/target/const_generics.rs
@@ -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;
+}