Skip to content

Commit

Permalink
cleaned up tests by bringing objects under mini_core into scope
Browse files Browse the repository at this point in the history
  • Loading branch information
madhav-madhusoodanan committed Feb 26, 2025
1 parent fcac229 commit 5686361
Show file tree
Hide file tree
Showing 21 changed files with 112 additions and 943 deletions.
109 changes: 57 additions & 52 deletions example/mini_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ impl<T: ?Sized> LegacyReceiver for &T {}
impl<T: ?Sized> LegacyReceiver for &mut T {}
impl<T: ?Sized, A: Allocator> LegacyReceiver for Box<T, A> {}

#[lang = "receiver"]
trait Receiver {
}

#[lang = "copy"]
pub trait Copy {}

Expand Down Expand Up @@ -139,6 +143,14 @@ impl Mul for usize {
}
}

impl Mul for isize {
type Output = Self;

fn mul(self, rhs: Self) -> Self::Output {
self * rhs
}
}

#[lang = "add"]
pub trait Add<RHS = Self> {
type Output;
Expand All @@ -162,6 +174,14 @@ impl Add for i8 {
}
}

impl Add for i32 {
type Output = Self;

fn add(self, rhs: Self) -> Self {
self + rhs
}
}

impl Add for usize {
type Output = Self;

Expand Down Expand Up @@ -193,6 +213,14 @@ impl Sub for usize {
}
}

impl Sub for isize {
type Output = Self;

fn sub(self, rhs: Self) -> Self {
self - rhs
}
}

impl Sub for u8 {
type Output = Self;

Expand Down Expand Up @@ -588,70 +616,43 @@ pub union MaybeUninit<T> {

pub mod intrinsics {
#[rustc_intrinsic]
#[rustc_intrinsic_must_be_overridden]
pub fn abort() -> ! {
loop {}
}
pub fn abort() -> !;

#[rustc_intrinsic]
#[rustc_intrinsic_must_be_overridden]
pub fn size_of<T>() -> usize {
loop {}
}
pub fn size_of<T>() -> usize;

#[rustc_intrinsic]
#[rustc_intrinsic_must_be_overridden]
pub unsafe fn size_of_val<T: ?::Sized>(_val: *const T) -> usize {
loop {}
}
pub unsafe fn size_of_val<T: ?::Sized>(_val: *const T) -> usize;

#[rustc_intrinsic]
#[rustc_intrinsic_must_be_overridden]
pub fn min_align_of<T>() -> usize {
loop {}
}
pub fn min_align_of<T>() -> usize;

#[rustc_intrinsic]
#[rustc_intrinsic_must_be_overridden]
pub unsafe fn min_align_of_val<T: ?::Sized>(_val: *const T) -> usize {
loop {}
}
pub unsafe fn min_align_of_val<T: ?::Sized>(_val: *const T) -> usize;

#[rustc_intrinsic]
#[rustc_intrinsic_must_be_overridden]
pub unsafe fn copy<T>(_src: *const T, _dst: *mut T, _count: usize) {
loop {}
}
pub unsafe fn copy<T>(_src: *const T, _dst: *mut T, _count: usize);

#[rustc_intrinsic]
#[rustc_intrinsic_must_be_overridden]
pub unsafe fn transmute<T, U>(_e: T) -> U {
loop {}
}
pub unsafe fn transmute<T, U>(_e: T) -> U;

#[rustc_intrinsic]
#[rustc_intrinsic_must_be_overridden]
pub unsafe fn ctlz_nonzero<T>(_x: T) -> u32 {
loop {}
}
pub unsafe fn ctlz_nonzero<T>(_x: T) -> u32;

#[rustc_intrinsic]
#[rustc_intrinsic_must_be_overridden]
pub fn needs_drop<T: ?::Sized>() -> bool {
loop {}
}
pub fn needs_drop<T: ?::Sized>() -> bool;

#[rustc_intrinsic]
#[rustc_intrinsic_must_be_overridden]
pub fn bitreverse<T>(_x: T) -> T {
loop {}
}
pub fn bitreverse<T>(_x: T) -> T;

#[rustc_intrinsic]
#[rustc_intrinsic_must_be_overridden]
pub fn bswap<T>(_x: T) -> T {
loop {}
}
pub fn bswap<T>(_x: T) -> T;

#[rustc_intrinsic]
#[rustc_intrinsic_must_be_overridden]
pub unsafe fn write_bytes<T>(_dst: *mut T, _val: u8, _count: usize) {
loop {}
}
pub unsafe fn write_bytes<T>(_dst: *mut T, _val: u8, _count: usize);

#[rustc_intrinsic]
#[rustc_intrinsic_must_be_overridden]
pub unsafe fn unreachable() -> ! {
loop {}
}
pub unsafe fn unreachable() -> !;
}

pub mod libc {
Expand All @@ -664,6 +665,10 @@ pub mod libc {
pub fn memcpy(dst: *mut u8, src: *const u8, size: usize);
pub fn memmove(dst: *mut u8, src: *const u8, size: usize);
pub fn strncpy(dst: *mut u8, src: *const u8, size: usize);
pub fn fflush(stream: *mut i32) -> i32;
pub fn exit(status: i32);

pub static stdout: *mut i32;
}
}

Expand Down
38 changes: 2 additions & 36 deletions tests/run/abort1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,11 @@

#![feature(auto_traits, lang_items, no_core, start, intrinsics, rustc_attrs)]
#![allow(internal_features)]

#![no_std]
#![no_core]

/*
* Core
*/

// Because we don't have core yet.
#[lang = "sized"]
pub trait Sized {}

#[lang = "copy"]
trait Copy {
}

impl Copy for isize {}

#[lang = "receiver"]
trait Receiver {
}

#[lang = "freeze"]
pub(crate) unsafe auto trait Freeze {}

mod intrinsics {
use super::Sized;

#[rustc_nounwind]
#[rustc_intrinsic]
#[rustc_intrinsic_must_be_overridden]
pub fn abort() -> ! {
loop {}
}
}

/*
* Code
*/
extern crate mini_core;
use mini_core::*;

fn test_fail() -> ! {
unsafe { intrinsics::abort() };
Expand Down
38 changes: 2 additions & 36 deletions tests/run/abort2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,11 @@

#![feature(auto_traits, lang_items, no_core, start, intrinsics, rustc_attrs)]
#![allow(internal_features)]

#![no_std]
#![no_core]

/*
* Core
*/

// Because we don't have core yet.
#[lang = "sized"]
pub trait Sized {}

#[lang = "copy"]
trait Copy {
}

impl Copy for isize {}

#[lang = "receiver"]
trait Receiver {
}

#[lang = "freeze"]
pub(crate) unsafe auto trait Freeze {}

mod intrinsics {
use super::Sized;

#[rustc_nounwind]
#[rustc_intrinsic]
#[rustc_intrinsic_must_be_overridden]
pub fn abort() -> ! {
loop {}
}
}

/*
* Code
*/
extern crate mini_core;
use mini_core::*;

fn fail() -> i32 {
unsafe { intrinsics::abort() };
Expand Down
9 changes: 1 addition & 8 deletions tests/run/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@
#![no_core]

extern crate mini_core;

mod libc {
#[link(name = "c")]
extern "C" {
pub fn printf(format: *const i8, ...) -> i32;
pub fn puts(s: *const u8) -> i32;
}
}
use mini_core::*;

static mut ONE: usize = 1;

Expand Down
Loading

0 comments on commit 5686361

Please sign in to comment.