Unnamed repository; edit this file 'description' to name the repository.
Fix empty generic param list for generate_function
Example
---
```rust
struct Foo<S>(S);
impl<S> Foo<S> {
fn foo(&self) {
self.bar()$0;
}
}
```
**Before this PR**:
```rust
struct Foo<S>(S);
impl<S> Foo<S> {
fn foo(&self) {
self.bar();
}
fn bar<>(&self) ${0:-> _} {
todo!()
}
}
```
**After this PR**:
```rust
struct Foo<S>(S);
impl<S> Foo<S> {
fn foo(&self) {
self.bar();
}
fn bar(&self) ${0:-> _} {
todo!()
}
}
```
| -rw-r--r-- | crates/ide-assists/src/handlers/generate_function.rs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/crates/ide-assists/src/handlers/generate_function.rs b/crates/ide-assists/src/handlers/generate_function.rs index 88ed6f9ce1..a9cf2c1bae 100644 --- a/crates/ide-assists/src/handlers/generate_function.rs +++ b/crates/ide-assists/src/handlers/generate_function.rs @@ -364,11 +364,13 @@ impl FunctionBuilder { Visibility::Crate => Some(make::visibility_pub_crate()), Visibility::Pub => Some(make::visibility_pub()), }; + let type_params = + self.generic_param_list.filter(|list| list.generic_params().next().is_some()); let fn_def = make::fn_( None, visibility, self.fn_name, - self.generic_param_list, + type_params, self.where_clause, self.params, self.fn_body, @@ -2416,6 +2418,33 @@ impl Foo { } #[test] + fn create_method_with_unused_generics() { + check_assist( + generate_function, + r#" +struct Foo<S>(S); +impl<S> Foo<S> { + fn foo(&self) { + self.bar()$0; + } +} +"#, + r#" +struct Foo<S>(S); +impl<S> Foo<S> { + fn foo(&self) { + self.bar(); + } + + fn bar(&self) ${0:-> _} { + todo!() + } +} +"#, + ) + } + + #[test] fn create_function_with_async() { check_assist( generate_function, |