Skip to content

Commit d0b95bd

Browse files
committed
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!() } } ```
1 parent 07b68bd commit d0b95bd

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

crates/ide-assists/src/handlers/generate_function.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,13 @@ impl FunctionBuilder {
364364
Visibility::Crate => Some(make::visibility_pub_crate()),
365365
Visibility::Pub => Some(make::visibility_pub()),
366366
};
367+
let type_params =
368+
self.generic_param_list.filter(|list| list.generic_params().next().is_some());
367369
let fn_def = make::fn_(
368370
None,
369371
visibility,
370372
self.fn_name,
371-
self.generic_param_list,
373+
type_params,
372374
self.where_clause,
373375
self.params,
374376
self.fn_body,
@@ -2415,6 +2417,33 @@ impl Foo {
24152417
)
24162418
}
24172419

2420+
#[test]
2421+
fn create_method_with_unused_generics() {
2422+
check_assist(
2423+
generate_function,
2424+
r#"
2425+
struct Foo<S>(S);
2426+
impl<S> Foo<S> {
2427+
fn foo(&self) {
2428+
self.bar()$0;
2429+
}
2430+
}
2431+
"#,
2432+
r#"
2433+
struct Foo<S>(S);
2434+
impl<S> Foo<S> {
2435+
fn foo(&self) {
2436+
self.bar();
2437+
}
2438+
2439+
fn bar(&self) ${0:-> _} {
2440+
todo!()
2441+
}
2442+
}
2443+
"#,
2444+
)
2445+
}
2446+
24182447
#[test]
24192448
fn create_function_with_async() {
24202449
check_assist(

0 commit comments

Comments
 (0)