Skip to content

Commit eca5905

Browse files
authored
Merge pull request #20132 from A4-Tacks/asmut-borrow-minicore
Add AsMut, Borrow and BorrowMut to minicore and famous_defs
2 parents 37f2263 + 1d7fde3 commit eca5905

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/tools/rust-analyzer/crates/ide-db/src/famous_defs.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ impl FamousDefs<'_, '_> {
106106
self.find_trait("core:convert:AsRef")
107107
}
108108

109+
pub fn core_convert_AsMut(&self) -> Option<Trait> {
110+
self.find_trait("core:convert:AsMut")
111+
}
112+
113+
pub fn core_borrow_Borrow(&self) -> Option<Trait> {
114+
self.find_trait("core:borrow:Borrow")
115+
}
116+
117+
pub fn core_borrow_BorrowMut(&self) -> Option<Trait> {
118+
self.find_trait("core:borrow:BorrowMut")
119+
}
120+
109121
pub fn core_ops_ControlFlow(&self) -> Option<Enum> {
110122
self.find_enum("core:ops:ControlFlow")
111123
}

src/tools/rust-analyzer/crates/test-utils/src/minicore.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
//! add:
1212
//! asm:
1313
//! assert:
14+
//! as_mut: sized
1415
//! as_ref: sized
1516
//! async_fn: fn, tuple, future, copy
1617
//! bool_impl: option, fn
1718
//! builtin_impls:
19+
//! borrow: sized
20+
//! borrow_mut: borrow
1821
//! cell: copy, drop
1922
//! clone: sized
2023
//! coerce_pointee: derive, sized, unsize, coerce_unsized, dispatch_from_dyn
@@ -380,11 +383,30 @@ pub mod convert {
380383
fn as_ref(&self) -> &T;
381384
}
382385
// endregion:as_ref
386+
// region:as_mut
387+
pub trait AsMut<T: crate::marker::PointeeSized>: crate::marker::PointeeSized {
388+
fn as_mut(&mut self) -> &mut T;
389+
}
390+
// endregion:as_mut
383391
// region:infallible
384392
pub enum Infallible {}
385393
// endregion:infallible
386394
}
387395

396+
pub mod borrow {
397+
// region:borrow
398+
pub trait Borrow<Borrowed: ?Sized> {
399+
fn borrow(&self) -> &Borrowed;
400+
}
401+
// endregion:borrow
402+
403+
// region:borrow_mut
404+
pub trait BorrowMut<Borrowed: ?Sized>: Borrow<Borrowed> {
405+
fn borrow_mut(&mut self) -> &mut Borrowed;
406+
}
407+
// endregion:borrow_mut
408+
}
409+
388410
pub mod mem {
389411
// region:manually_drop
390412
use crate::marker::PointeeSized;

0 commit comments

Comments
 (0)