mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-02 04:48:13 +00:00
fix: generate delegate methods filters out functions that already exist
on the struct's impls
This commit is contained in:
parent
2fdd1ac510
commit
a86c431f45
2 changed files with 30 additions and 2 deletions
|
|
@ -86,7 +86,8 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'
|
|||
for method in methods {
|
||||
let adt = ast::Adt::Struct(strukt.clone());
|
||||
let name = method.name(ctx.db()).to_string();
|
||||
let impl_def = find_struct_impl(ctx, &adt, &[name]).flatten();
|
||||
// if `find_struct_impl` returns None, that means that a function named `name` already exists.
|
||||
let Some(impl_def) = find_struct_impl(ctx, &adt, &[name]) else { continue; };
|
||||
acc.add_group(
|
||||
&GroupLabel("Generate delegate methods…".to_owned()),
|
||||
AssistId("generate_delegate_methods", AssistKind::Generate),
|
||||
|
|
@ -380,4 +381,26 @@ struct Person {
|
|||
}"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_generate_not_eligible_if_fn_exists() {
|
||||
check_assist_not_applicable(
|
||||
generate_delegate_methods,
|
||||
r#"
|
||||
struct Age(u8);
|
||||
impl Age {
|
||||
fn age(&self) -> u8 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
struct Person {
|
||||
ag$0e: Age,
|
||||
}
|
||||
impl Person {
|
||||
fn age(&self) -> u8 { 0 }
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue