mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-28 10:39:45 +00:00
Observe unsafeness only for replace_derive_with_manual_impl
This commit is contained in:
parent
477b987179
commit
824df43d2d
3 changed files with 6 additions and 34 deletions
|
|
@ -2363,33 +2363,4 @@ impl other_file_2::Trait for MyStruct {
|
||||||
}"#,
|
}"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn unsafeness_observed() {
|
|
||||||
check_assist(
|
|
||||||
add_missing_impl_members,
|
|
||||||
r#"
|
|
||||||
unsafe trait UnsafeTrait {
|
|
||||||
unsafe fn unsafe_fn();
|
|
||||||
}
|
|
||||||
|
|
||||||
struct A {}
|
|
||||||
|
|
||||||
impl Uns$0afeTrait for A {}
|
|
||||||
"#,
|
|
||||||
r#"
|
|
||||||
unsafe trait UnsafeTrait {
|
|
||||||
unsafe fn unsafe_fn();
|
|
||||||
}
|
|
||||||
|
|
||||||
struct A {}
|
|
||||||
|
|
||||||
unsafe impl UnsafeTrait for A {
|
|
||||||
unsafe fn unsafe_fn() {
|
|
||||||
${0:todo!()}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use syntax::{
|
||||||
SyntaxKind::WHITESPACE,
|
SyntaxKind::WHITESPACE,
|
||||||
T,
|
T,
|
||||||
ast::{self, AstNode, HasName, make},
|
ast::{self, AstNode, HasName, make},
|
||||||
ted,
|
ted::{self, Position},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
@ -223,6 +223,10 @@ fn impl_def_from_trait(
|
||||||
let first_assoc_item =
|
let first_assoc_item =
|
||||||
add_trait_assoc_items_to_impl(sema, &trait_items, trait_, &impl_def, &target_scope);
|
add_trait_assoc_items_to_impl(sema, &trait_items, trait_, &impl_def, &target_scope);
|
||||||
|
|
||||||
|
if trait_.is_unsafe(sema.db) {
|
||||||
|
ted::insert(Position::first_child_of(impl_def.syntax()), make::token(T![unsafe]));
|
||||||
|
}
|
||||||
|
|
||||||
// Generate a default `impl` function body for the derived trait.
|
// Generate a default `impl` function body for the derived trait.
|
||||||
if let ast::AssocItem::Fn(ref func) = first_assoc_item {
|
if let ast::AssocItem::Fn(ref func) = first_assoc_item {
|
||||||
let _ = gen_trait_fn_body(func, trait_path, adt, None);
|
let _ = gen_trait_fn_body(func, trait_path, adt, None);
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ use syntax::{
|
||||||
make,
|
make,
|
||||||
syntax_factory::SyntaxFactory,
|
syntax_factory::SyntaxFactory,
|
||||||
},
|
},
|
||||||
ted::{self, Position},
|
ted,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::assist_context::{AssistContext, SourceChangeBuilder};
|
use crate::assist_context::{AssistContext, SourceChangeBuilder};
|
||||||
|
|
@ -212,9 +212,6 @@ pub fn add_trait_assoc_items_to_impl(
|
||||||
});
|
});
|
||||||
|
|
||||||
let assoc_item_list = impl_.get_or_create_assoc_item_list();
|
let assoc_item_list = impl_.get_or_create_assoc_item_list();
|
||||||
if trait_.is_unsafe(sema.db) {
|
|
||||||
ted::insert(Position::first_child_of(impl_.syntax()), make::token(T![unsafe]));
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut first_item = None;
|
let mut first_item = None;
|
||||||
for item in items {
|
for item in items {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue