mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 11:20:54 +00:00
Add Deref -> DerefMut for generate_mut_trait_impl
This commit is contained in:
parent
1520876545
commit
dfd8434847
@ -134,6 +134,9 @@ fn get_trait_mut(apply_trait: &hir::Trait, famous: FamousDefs<'_, '_>) -> Option
|
||||
if trait_ == famous.core_borrow_Borrow().as_ref() {
|
||||
return Some("BorrowMut");
|
||||
}
|
||||
if trait_ == famous.core_ops_Deref().as_ref() {
|
||||
return Some("DerefMut");
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
@ -142,6 +145,7 @@ fn process_method_name(name: ast::Name) -> Option<(ast::Name, &'static str)> {
|
||||
"index" => "index_mut",
|
||||
"as_ref" => "as_mut",
|
||||
"borrow" => "borrow_mut",
|
||||
"deref" => "deref_mut",
|
||||
_ => return None,
|
||||
};
|
||||
Some((name, new_name))
|
||||
@ -258,6 +262,39 @@ impl core::convert::AsRef<i32> for Foo {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
||||
check_assist(
|
||||
generate_mut_trait_impl,
|
||||
r#"
|
||||
//- minicore: deref
|
||||
struct Foo(i32);
|
||||
|
||||
impl core::ops::Deref$0 for Foo {
|
||||
type Target = i32;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
struct Foo(i32);
|
||||
|
||||
$0impl core::ops::DerefMut for Foo {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::Deref for Foo {
|
||||
type Target = i32;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user