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 507b29f
Show file tree
Hide file tree
Showing 18 changed files with 110 additions and 885 deletions.
108 changes: 56 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,9 @@ 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 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
114 changes: 2 additions & 112 deletions tests/run/assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,120 +7,11 @@

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

#![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 {}
impl Copy for *mut i32 {}
impl Copy for usize {}
impl Copy for u8 {}
impl Copy for i8 {}
impl Copy for i32 {}

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

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

#[lang = "panic_location"]
struct PanicLocation {
file: &'static str,
line: u32,
column: u32,
}

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

pub static stdout: *mut i32;
}
}

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

#[lang = "panic"]
#[track_caller]
#[no_mangle]
pub fn panic(_msg: &'static str) -> ! {
unsafe {
libc::puts("Panicking\0" as *const str as *const u8);
libc::fflush(libc::stdout);
intrinsics::abort();
}
}

#[lang = "add"]
trait Add<RHS = Self> {
type Output;

fn add(self, rhs: RHS) -> Self::Output;
}

impl Add for u8 {
type Output = Self;

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

impl Add for i8 {
type Output = Self;

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

impl Add for i32 {
type Output = Self;

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

impl Add for usize {
type Output = Self;

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

impl Add for isize {
type Output = Self;

fn add(self, rhs: Self) -> Self {
self + rhs
}
}
extern crate mini_core;
use mini_core::*;

#[track_caller]
#[lang = "panic_const_add_overflow"]
Expand All @@ -141,7 +32,6 @@ fn inc(num: isize) -> isize {
num + 1
}


#[start]
fn main(mut argc: isize, _argv: *const *const u8) -> isize {
argc = inc(argc);
Expand Down
Loading

0 comments on commit 507b29f

Please sign in to comment.