mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 11:20:54 +00:00
Observe unsafeness when generating manual impls of former derives
This commit is contained in:
parent
0c1b4838ce
commit
477b987179
@ -2363,4 +2363,33 @@ 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!()}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use syntax::{
|
||||
make,
|
||||
syntax_factory::SyntaxFactory,
|
||||
},
|
||||
ted,
|
||||
ted::{self, Position},
|
||||
};
|
||||
|
||||
use crate::assist_context::{AssistContext, SourceChangeBuilder};
|
||||
@ -212,6 +212,10 @@ pub fn add_trait_assoc_items_to_impl(
|
||||
});
|
||||
|
||||
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;
|
||||
for item in items {
|
||||
first_item.get_or_insert_with(|| item.clone());
|
||||
|
@ -1276,7 +1276,7 @@ pub mod tokens {
|
||||
|
||||
pub(super) static SOURCE_FILE: LazyLock<Parse<SourceFile>> = LazyLock::new(|| {
|
||||
SourceFile::parse(
|
||||
"use crate::foo; const C: <()>::Item = ( true && true , true || true , 1 != 1, 2 == 2, 3 < 3, 4 <= 4, 5 > 5, 6 >= 6, !true, *p, &p , &mut p, async { let _ @ [] })\n;\n\nimpl A for B where: {}",
|
||||
"use crate::foo; const C: <()>::Item = ( true && true , true || true , 1 != 1, 2 == 2, 3 < 3, 4 <= 4, 5 > 5, 6 >= 6, !true, *p, &p , &mut p, async { let _ @ [] })\n;\n\nunsafe impl A for B where: {}",
|
||||
Edition::CURRENT,
|
||||
)
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user