Skip to content

Add AsMut, Borrow and BorrowMut to minicore and famous_defs #20132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions crates/ide-db/src/famous_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ impl FamousDefs<'_, '_> {
self.find_trait("core:convert:AsRef")
}

pub fn core_convert_AsMut(&self) -> Option<Trait> {
self.find_trait("core:convert:AsMut")
}

pub fn core_borrow_Borrow(&self) -> Option<Trait> {
self.find_trait("core:borrow:Borrow")
}

pub fn core_borrow_BorrowMut(&self) -> Option<Trait> {
self.find_trait("core:borrow:BorrowMut")
}

pub fn core_ops_ControlFlow(&self) -> Option<Enum> {
self.find_enum("core:ops:ControlFlow")
}
Expand Down
22 changes: 22 additions & 0 deletions crates/test-utils/src/minicore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
//! add:
//! asm:
//! assert:
//! as_mut: sized
//! as_ref: sized
//! async_fn: fn, tuple, future, copy
//! bool_impl: option, fn
//! builtin_impls:
//! borrow: sized
//! borrow_mut: borrow
//! cell: copy, drop
//! clone: sized
//! coerce_pointee: derive, sized, unsize, coerce_unsized, dispatch_from_dyn
Expand Down Expand Up @@ -377,11 +380,30 @@ pub mod convert {
fn as_ref(&self) -> &T;
}
// endregion:as_ref
// region:as_mut
pub trait AsMut<T: crate::marker::PointeeSized>: crate::marker::PointeeSized {
fn as_mut(&mut self) -> &mut T;
}
// endregion:as_mut
// region:infallible
pub enum Infallible {}
// endregion:infallible
}

pub mod borrow {
// region:borrow
pub trait Borrow<Borrowed: ?Sized> {
fn borrow(&self) -> &Borrowed;
}
// endregion:borrow

// region:borrow_mut
pub trait BorrowMut<Borrowed: ?Sized>: Borrow<Borrowed> {
fn borrow_mut(&mut self) -> &mut Borrowed;
}
// endregion:borrow_mut
}

pub mod mem {
// region:manually_drop
use crate::marker::PointeeSized;
Expand Down