Skip to content
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

Cleaned up tests by bringing objects under mini_core into scope #639

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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]
Copy link
Author

@madhav-madhusoodanan madhav-madhusoodanan Feb 26, 2025

Choose a reason for hiding this comment

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

@antoyo is the #[rustc_nounwind] annotation useful for functions within the intrinsics module?

#[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