mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 14:03:35 +00:00
Auto merge of #16067 - roife:fix-introduce-named-generic-impl-inside-types, r=Veykril
fix: no code action 'introduce_named_generic' for impl inside types Fix #15734. ### Changes Made - Find params in `ancestors` instead of just `parent` - Added tests (`replace_impl_with_mut` and `replace_impl_inside`)
This commit is contained in:
commit
e53a115fe1
1 changed files with 19 additions and 1 deletions
|
@ -18,7 +18,7 @@ use crate::{utils::suggest_name, AssistContext, AssistId, AssistKind, Assists};
|
|||
// ```
|
||||
pub(crate) fn introduce_named_generic(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
|
||||
let impl_trait_type = ctx.find_node_at_offset::<ast::ImplTraitType>()?;
|
||||
let param = impl_trait_type.syntax().parent().and_then(ast::Param::cast)?;
|
||||
let param = impl_trait_type.syntax().ancestors().find_map(|node| ast::Param::cast(node))?;
|
||||
let fn_ = param.syntax().ancestors().find_map(ast::Fn::cast)?;
|
||||
|
||||
let type_bound_list = impl_trait_type.type_bound_list()?;
|
||||
|
@ -149,4 +149,22 @@ fn foo<
|
|||
r#"fn foo<$0F: Foo + Bar>(bar: F) {}"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replace_impl_with_mut() {
|
||||
check_assist(
|
||||
introduce_named_generic,
|
||||
r#"fn f(iter: &mut $0impl Iterator<Item = i32>) {}"#,
|
||||
r#"fn f<$0I: Iterator<Item = i32>>(iter: &mut I) {}"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replace_impl_inside() {
|
||||
check_assist(
|
||||
introduce_named_generic,
|
||||
r#"fn f(x: &mut Vec<$0impl Iterator<Item = i32>>) {}"#,
|
||||
r#"fn f<$0I: Iterator<Item = i32>>(x: &mut Vec<I>) {}"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue