Skip to content

Commit 824df43

Browse files
committed
Observe unsafeness only for replace_derive_with_manual_impl
1 parent 477b987 commit 824df43

File tree

3 files changed

+6
-34
lines changed

3 files changed

+6
-34
lines changed

crates/ide-assists/src/handlers/add_missing_impl_members.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,33 +2363,4 @@ impl other_file_2::Trait for MyStruct {
23632363
}"#,
23642364
);
23652365
}
2366-
2367-
#[test]
2368-
fn unsafeness_observed() {
2369-
check_assist(
2370-
add_missing_impl_members,
2371-
r#"
2372-
unsafe trait UnsafeTrait {
2373-
unsafe fn unsafe_fn();
2374-
}
2375-
2376-
struct A {}
2377-
2378-
impl Uns$0afeTrait for A {}
2379-
"#,
2380-
r#"
2381-
unsafe trait UnsafeTrait {
2382-
unsafe fn unsafe_fn();
2383-
}
2384-
2385-
struct A {}
2386-
2387-
unsafe impl UnsafeTrait for A {
2388-
unsafe fn unsafe_fn() {
2389-
${0:todo!()}
2390-
}
2391-
}
2392-
"#,
2393-
);
2394-
}
23952366
}

crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use syntax::{
55
SyntaxKind::WHITESPACE,
66
T,
77
ast::{self, AstNode, HasName, make},
8-
ted,
8+
ted::{self, Position},
99
};
1010

1111
use crate::{
@@ -223,6 +223,10 @@ fn impl_def_from_trait(
223223
let first_assoc_item =
224224
add_trait_assoc_items_to_impl(sema, &trait_items, trait_, &impl_def, &target_scope);
225225

226+
if trait_.is_unsafe(sema.db) {
227+
ted::insert(Position::first_child_of(impl_def.syntax()), make::token(T![unsafe]));
228+
}
229+
226230
// Generate a default `impl` function body for the derived trait.
227231
if let ast::AssocItem::Fn(ref func) = first_assoc_item {
228232
let _ = gen_trait_fn_body(func, trait_path, adt, None);

crates/ide-assists/src/utils.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use syntax::{
2424
make,
2525
syntax_factory::SyntaxFactory,
2626
},
27-
ted::{self, Position},
27+
ted,
2828
};
2929

3030
use crate::assist_context::{AssistContext, SourceChangeBuilder};
@@ -212,9 +212,6 @@ pub fn add_trait_assoc_items_to_impl(
212212
});
213213

214214
let assoc_item_list = impl_.get_or_create_assoc_item_list();
215-
if trait_.is_unsafe(sema.db) {
216-
ted::insert(Position::first_child_of(impl_.syntax()), make::token(T![unsafe]));
217-
}
218215

219216
let mut first_item = None;
220217
for item in items {

0 commit comments

Comments
 (0)