Skip to content

Commit

Permalink
Auto merge of rust-lang#13576 - Bben01:supress_missing_impl_inside_bl…
Browse files Browse the repository at this point in the history
…ock, r=jonas-schievink

Suppress "Implement default members" inside contained items

Fixes rust-lang#13561
  • Loading branch information
bors committed Nov 24, 2022
2 parents 81d26e7 + 95b4a74 commit 63a676e
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions crates/ide-assists/src/handlers/add_missing_impl_members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down Expand Up @@ -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) {}
}"#,
)
}
}

0 comments on commit 63a676e

Please sign in to comment.