Merge pull request #20653 from A4-Tacks/gen-function-empty-gen-param

Fix empty generic param list for generate_function
This commit is contained in:
Laurențiu Nicola 2025-09-11 05:08:00 +00:00 committed by GitHub
commit 7f38c057dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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(