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!()
}
}
```
This commit is contained in:
parent
8764ecfe99
commit
2d87bc3e6b
1 changed files with 30 additions and 1 deletions
|
|
@ -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,
|
||||
|
|
@ -2415,6 +2417,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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue