Skip to content

Commit 71a56a5

Browse files
committed
[PAC] Minicore updates to support fn ptr type discriminator tests
1 parent 17ad6d3 commit 71a56a5

1 file changed

Lines changed: 42 additions & 12 deletions

File tree

tests/auxiliary/minicore.rs

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ impl<T: Copy, const N: usize> Copy for [T; N] {}
112112
pub struct PhantomData<T: PointeeSized>;
113113
impl<T: PointeeSized> Copy for PhantomData<T> {}
114114

115+
#[rustc_diagnostic_item = "Option"]
115116
pub enum Option<T> {
116117
None,
117118
Some(T),
@@ -249,11 +250,18 @@ pub trait Add<Rhs = Self> {
249250
fn add(self, _: Rhs) -> Self::Output;
250251
}
251252

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

255257
fn add(self, other: isize) -> isize {
256-
7 // avoid needing to add all of the overflow handling and panic language items
258+
7
259+
}
260+
}
261+
impl Add for i32 {
262+
type Output = i32;
263+
fn add(self, rhs: i32) -> i32 {
264+
7
257265
}
258266
}
259267

@@ -300,18 +308,30 @@ impl_marker_trait!(
300308
);
301309

302310
impl Sync for () {}
303-
304311
impl<T, const N: usize> Sync for [T; N] {}
312+
impl<T: Sync> Sync for Option<T> {}
313+
impl<T: ?Sized + Sync> Sync for &T {}
314+
305315
// Function pointers are treated as `Sync` to match real `core` behavior.
306316
//
307317
// Minicore provides only the minimal set of impls required by tests. Rather
308318
// than exhaustively covering all possible function pointer signatures,
309-
// additional impls should be added as needed.
310-
impl<R> Sync for fn() -> R {}
311-
impl<R> Sync for extern "C" fn() -> R {}
312-
impl<R> Sync for unsafe extern "C" fn() -> R {}
313-
impl<A, R> Sync for extern "C" fn(A) -> R {}
314-
impl<A, R> Sync for unsafe extern "C" fn(A) -> R {}
319+
// additional arities should be added as needed.
320+
macro_rules! impl_sync_for_fn_ptrs {
321+
($(($($T:ident),*)),* $(,)?) => {
322+
$(
323+
impl<$($T,)* R> Sync for fn($($T),*) -> R {}
324+
325+
impl<$($T,)* R> Sync for extern "C" fn($($T),*) -> R {}
326+
impl<$($T,)* R> Sync for unsafe extern "C" fn($($T),*) -> R {}
327+
328+
impl<$($T,)* R> Sync for extern "C" fn($($T,)* ...) -> R {}
329+
impl<$($T,)* R> Sync for unsafe extern "C" fn($($T,)* ...) -> R {}
330+
)*
331+
};
332+
}
333+
334+
impl_sync_for_fn_ptrs!((), (A), (A, B), (A, B, C), (A, B, C, D),);
315335

316336
#[lang = "drop_glue"]
317337
fn drop_glue<T>(_: &mut T) {}
@@ -348,7 +368,7 @@ pub trait CoerceUnsized<T: PointeeSized> {}
348368
impl<'a, 'b: 'a, T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<&'a U> for &'b T {}
349369

350370
#[lang = "drop"]
351-
trait Drop {
371+
pub trait Drop {
352372
fn drop(&mut self);
353373
}
354374

@@ -359,7 +379,7 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
359379
pub mod mem {
360380
#[rustc_nounwind]
361381
#[rustc_intrinsic]
362-
pub unsafe fn transmute<Src, Dst>(src: Src) -> Dst;
382+
pub const unsafe fn transmute<Src, Dst>(src: Src) -> Dst;
363383

364384
#[rustc_nounwind]
365385
#[rustc_intrinsic]
@@ -378,6 +398,15 @@ pub mod ptr {
378398

379399
unsafe { volatile_store(dst, src) };
380400
}
401+
402+
#[inline]
403+
#[rustc_diagnostic_item = "ptr_read_volatile"]
404+
pub unsafe fn read_volatile<T>(src: *const T) -> T {
405+
#[rustc_intrinsic]
406+
pub unsafe fn volatile_load<T>(src: *const T) -> T;
407+
408+
unsafe { volatile_load(src) }
409+
}
381410
}
382411

383412
pub mod hint {
@@ -392,9 +421,10 @@ pub mod hint {
392421

393422
#[lang = "c_void"]
394423
#[repr(u8)]
424+
#[allow(non_camel_case_types)]
395425
pub enum c_void {
396-
__variant1,
397-
__variant2,
426+
Variant1,
427+
Variant2,
398428
}
399429

400430
#[rustc_builtin_macro(pattern_type)]

0 commit comments

Comments
 (0)