Skip to content
Open
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
53 changes: 42 additions & 11 deletions tests/auxiliary/minicore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ pub mod arch {
pub struct PhantomData<T: PointeeSized>;
impl<T: PointeeSized> Copy for PhantomData<T> {}

#[rustc_diagnostic_item = "Option"]
#[lang = "Option"]
pub enum Option<T> {
None,
Some(T),
Expand Down Expand Up @@ -302,11 +304,18 @@ pub trait Add<Rhs = Self> {
fn add(self, _: Rhs) -> Self::Output;
}

// Avoid needing to add all of the overflow handling and panic language items
impl Add<isize> for isize {
type Output = isize;

fn add(self, other: isize) -> isize {
7 // avoid needing to add all of the overflow handling and panic language items
7
}
}
impl Add for i32 {

@kovdan01 kovdan01 Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I failed to find direct uses of Add trait or add function in tests. Could you please explain why we need this new implementation for i32 here?

View changes since the review

@jchlanda jchlanda Jul 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because + operator is resolved to Add, so without the code above this will fail to compile for minicore:

extern "C" fn foo(x: i32) -> i32 {
    x + 1
}

type Output = i32;
fn add(self, rhs: i32) -> i32 {
7
}
}

Expand Down Expand Up @@ -353,18 +362,30 @@ impl_marker_trait!(
);

impl Sync for () {}

impl<T, const N: usize> Sync for [T; N] {}
impl<T: Sync> Sync for Option<T> {}
impl<T: ?Sized + Sync> Sync for &T {}

// Function pointers are treated as `Sync` to match real `core` behavior.
//
// Minicore provides only the minimal set of impls required by tests. Rather
// than exhaustively covering all possible function pointer signatures,
// additional impls should be added as needed.
impl<R> Sync for fn() -> R {}
impl<R> Sync for extern "C" fn() -> R {}
impl<R> Sync for unsafe extern "C" fn() -> R {}
impl<A, R> Sync for extern "C" fn(A) -> R {}
impl<A, R> Sync for unsafe extern "C" fn(A) -> R {}
// additional arities should be added as needed.
macro_rules! impl_sync_for_fn_ptrs {
($(($($T:ident),*)),* $(,)?) => {
$(
impl<$($T,)* R> Sync for fn($($T),*) -> R {}

impl<$($T,)* R> Sync for extern "C" fn($($T),*) -> R {}
impl<$($T,)* R> Sync for unsafe extern "C" fn($($T),*) -> R {}

impl<$($T,)* R> Sync for extern "C" fn($($T,)* ...) -> R {}
impl<$($T,)* R> Sync for unsafe extern "C" fn($($T,)* ...) -> R {}
)*
};
}

impl_sync_for_fn_ptrs!((), (A), (A, B), (A, B, C), (A, B, C, D),);

#[lang = "drop_glue"]
fn drop_glue<T>(_: &mut T) {}
Expand Down Expand Up @@ -401,7 +422,7 @@ pub trait CoerceUnsized<T: PointeeSized> {}
impl<'a, 'b: 'a, T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<&'a U> for &'b T {}

#[lang = "drop"]
trait Drop {
pub trait Drop {
fn drop(&mut self);
}

Expand Down Expand Up @@ -458,6 +479,15 @@ pub mod ptr {

unsafe { volatile_store(dst, src) };
}

#[inline]
#[rustc_diagnostic_item = "ptr_read_volatile"]
pub unsafe fn read_volatile<T>(src: *const T) -> T {
#[rustc_intrinsic]
pub unsafe fn volatile_load<T>(src: *const T) -> T;

unsafe { volatile_load(src) }
}
}

pub mod hint {
Expand Down Expand Up @@ -518,9 +548,10 @@ pub mod num {

#[lang = "c_void"]
#[repr(u8)]
#[allow(non_camel_case_types)]

@kovdan01 kovdan01 Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this change? I see c_void used in tests, but I'm not sure why these naming changes are required (the enum elements do not look directly used in tests anyway)

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without it tidy would fail (and it is run as part of PR CI tests).

pub enum c_void {
__variant1,
__variant2,
Variant1,
Variant2,
}

#[allow_internal_unstable(internal_syntax)]
Expand Down
Loading