Auto merge of #13576 - Bben01:supress_missing_impl_inside_block, r=jonas-schievink

Suppress "Implement default members" inside contained items

Fixes #13561
This commit is contained in:
bors 2022-11-24 15:16:36 +00:00
commit 63a676eedf

View File

@ -107,6 +107,14 @@ fn add_missing_impl_members_inner(
) -> Option<()> {
let _p = profile::span("add_missing_impl_members_inner");
let impl_def = ctx.find_node_at_offset::<ast::Impl>()?;
if ctx.token_at_offset().all(|t| {
t.parent_ancestors()
.any(|s| ast::BlockExpr::can_cast(s.kind()) || ast::ParamList::can_cast(s.kind()))
}) {
return None;
}
let target_scope = ctx.sema.scope(impl_def.syntax())?;
let trait_ = resolve_target_trait(&ctx.sema, &impl_def)?;
@ -1343,4 +1351,95 @@ impl PartialEq for SomeStruct {
"#,
);
}
#[test]
fn test_ignore_function_body() {
check_assist_not_applicable(
add_missing_default_members,
r#"
trait Trait {
type X;
fn foo(&self);
fn bar(&self) {}
}
impl Trait for () {
type X = u8;
fn foo(&self) {$0
let x = 5;
}
}"#,
)
}
#[test]
fn test_ignore_param_list() {
check_assist_not_applicable(
add_missing_impl_members,
r#"
trait Trait {
type X;
fn foo(&self);
fn bar(&self);
}
impl Trait for () {
type X = u8;
fn foo(&self$0) {
let x = 5;
}
}"#,
)
}
#[test]
fn test_ignore_scope_inside_function() {
check_assist_not_applicable(
add_missing_impl_members,
r#"
trait Trait {
type X;
fn foo(&self);
fn bar(&self);
}
impl Trait for () {
type X = u8;
fn foo(&self) {
let x = async {$0 5 };
}
}"#,
)
}
#[test]
fn test_apply_outside_function() {
check_assist(
add_missing_default_members,
r#"
trait Trait {
type X;
fn foo(&self);
fn bar(&self) {}
}
impl Trait for () {
type X = u8;
fn foo(&self)$0 {}
}"#,
r#"
trait Trait {
type X;
fn foo(&self);
fn bar(&self) {}
}
impl Trait for () {
type X = u8;
fn foo(&self) {}
$0fn bar(&self) {}
}"#,
)
}
}