aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-03-27 10:00:37 +0000
committerGitHub <[email protected]>2021-03-27 10:00:37 +0000
commitae9201431922fc7a705437df6d11153dd265f7eb (patch)
tree76750ded51991811d74f9ee7ef3e37d77c3d8b42
parentc8066ebd1781a6f6f536abe3494477bd69df795a (diff)
parent5a2ef8d0cad71cf51da548b80bcfb4ba615061d1 (diff)
Merge #8213
8213: Added support for const generics in impl generation r=Veykril a=ivan770 Closes #8211 Co-authored-by: ivan770 <[email protected]>
-rw-r--r--crates/ide_assists/src/handlers/generate_impl.rs17
-rw-r--r--crates/ide_assists/src/utils.rs9
2 files changed, 21 insertions, 5 deletions
diff --git a/crates/ide_assists/src/handlers/generate_impl.rs b/crates/ide_assists/src/handlers/generate_impl.rs
index a8e3c4fc2..fd2e250bc 100644
--- a/crates/ide_assists/src/handlers/generate_impl.rs
+++ b/crates/ide_assists/src/handlers/generate_impl.rs
@@ -72,6 +72,17 @@ mod tests {
72 check_assist( 72 check_assist(
73 generate_impl, 73 generate_impl,
74 r#" 74 r#"
75 struct MyOwnArray<T, const S: usize> {}$0"#,
76 r#"
77 struct MyOwnArray<T, const S: usize> {}
78
79 impl<T, const S: usize> MyOwnArray<T, S> {
80 $0
81 }"#,
82 );
83 check_assist(
84 generate_impl,
85 r#"
75 #[cfg(feature = "foo")] 86 #[cfg(feature = "foo")]
76 struct Foo<'a, T: Foo<'a>> {$0}"#, 87 struct Foo<'a, T: Foo<'a>> {$0}"#,
77 r#" 88 r#"
@@ -114,11 +125,11 @@ mod tests {
114 check_assist( 125 check_assist(
115 generate_impl, 126 generate_impl,
116 r#" 127 r#"
117 struct Defaulted<'a, 'b: 'a, T: Debug + Clone + 'a + 'b = String> {}$0"#, 128 struct Defaulted<'a, 'b: 'a, T: Debug + Clone + 'a + 'b = String, const S: usize> {}$0"#,
118 r#" 129 r#"
119 struct Defaulted<'a, 'b: 'a, T: Debug + Clone + 'a + 'b = String> {} 130 struct Defaulted<'a, 'b: 'a, T: Debug + Clone + 'a + 'b = String, const S: usize> {}
120 131
121 impl<'a, 'b: 'a, T: Debug + Clone + 'a + 'b> Defaulted<'a, 'b, T> { 132 impl<'a, 'b: 'a, T: Debug + Clone + 'a + 'b, const S: usize> Defaulted<'a, 'b, T, S> {
122 $0 133 $0
123 }"#, 134 }"#,
124 ); 135 );
diff --git a/crates/ide_assists/src/utils.rs b/crates/ide_assists/src/utils.rs
index 9de9e4dbd..5f630ec75 100644
--- a/crates/ide_assists/src/utils.rs
+++ b/crates/ide_assists/src/utils.rs
@@ -434,7 +434,8 @@ fn generate_impl_text_inner(adt: &ast::Adt, trait_text: Option<&str>, code: &str
434 } 434 }
435 buf 435 buf
436 }); 436 });
437 let generics = lifetimes.chain(type_params).format(", "); 437 let const_params = generic_params.const_params().map(|t| t.syntax().to_string());
438 let generics = lifetimes.chain(type_params).chain(const_params).format(", ");
438 format_to!(buf, "<{}>", generics); 439 format_to!(buf, "<{}>", generics);
439 } 440 }
440 buf.push(' '); 441 buf.push(' ');
@@ -452,7 +453,11 @@ fn generate_impl_text_inner(adt: &ast::Adt, trait_text: Option<&str>, code: &str
452 .type_params() 453 .type_params()
453 .filter_map(|it| it.name()) 454 .filter_map(|it| it.name())
454 .map(|it| SmolStr::from(it.text())); 455 .map(|it| SmolStr::from(it.text()));
455 format_to!(buf, "<{}>", lifetime_params.chain(type_params).format(", ")) 456 let const_params = generic_params
457 .const_params()
458 .filter_map(|it| it.name())
459 .map(|it| SmolStr::from(it.text()));
460 format_to!(buf, "<{}>", lifetime_params.chain(type_params).chain(const_params).format(", "))
456 } 461 }
457 462
458 match adt.where_clause() { 463 match adt.where_clause() {