aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-02-20 14:07:19 +0000
committerGitHub <[email protected]>2021-02-20 14:07:19 +0000
commit459e10eb74796aeae78c1e741289881365d360f0 (patch)
treec14787b0446e8c01d3794c796eb290bb4f208465
parentba3a5c518a4e20ddacad05d7a8a67704ca2b2a9a (diff)
parentd8559588c0a38ef1c2cfcb297b520469e6765c80 (diff)
Merge #7725
7725: fix(assist): display where predicates when we want to generate impl r=lnicola a=bnjjj close #7721 Co-authored-by: Benjamin Coenen <[email protected]>
-rw-r--r--crates/assists/src/handlers/generate_impl.rs25
-rw-r--r--crates/assists/src/utils.rs9
2 files changed, 33 insertions, 1 deletions
diff --git a/crates/assists/src/handlers/generate_impl.rs b/crates/assists/src/handlers/generate_impl.rs
index 16a600e6f..a8e3c4fc2 100644
--- a/crates/assists/src/handlers/generate_impl.rs
+++ b/crates/assists/src/handlers/generate_impl.rs
@@ -122,6 +122,31 @@ mod tests {
122 $0 122 $0
123 }"#, 123 }"#,
124 ); 124 );
125
126 check_assist(
127 generate_impl,
128 r#"pub trait Trait {}
129struct Struct<T>$0
130where
131 T: Trait,
132{
133 inner: T,
134}"#,
135 r#"pub trait Trait {}
136struct Struct<T>
137where
138 T: Trait,
139{
140 inner: T,
141}
142
143impl<T> Struct<T>
144where
145 T: Trait,
146{
147 $0
148}"#,
149 );
125 } 150 }
126 151
127 #[test] 152 #[test]
diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs
index 8418e6e12..0074da741 100644
--- a/crates/assists/src/utils.rs
+++ b/crates/assists/src/utils.rs
@@ -421,7 +421,14 @@ fn generate_impl_text_inner(adt: &ast::Adt, trait_text: Option<&str>, code: &str
421 format_to!(buf, "<{}>", lifetime_params.chain(type_params).format(", ")) 421 format_to!(buf, "<{}>", lifetime_params.chain(type_params).format(", "))
422 } 422 }
423 423
424 format_to!(buf, " {{\n{}\n}}", code); 424 match adt.where_clause() {
425 Some(where_clause) => {
426 format_to!(buf, "\n{}\n{{\n{}\n}}", where_clause, code);
427 }
428 None => {
429 format_to!(buf, " {{\n{}\n}}", code);
430 }
431 }
425 432
426 buf 433 buf
427} 434}