-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add minicore
test auxiliary and support //@ add-core-stubs
directive in ui/assembly/codegen tests
#130693
Add minicore
test auxiliary and support //@ add-core-stubs
directive in ui/assembly/codegen tests
#130693
Changes from all commits
82c2e42
f9ca420
74c0c48
95d01fc
a737f75
59cb59d
b115a22
a8b34f5
0bbe07e
adb6d47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
//! `compiletest` self-test to check that `add-core-stubs` is incompatible with run pass modes. | ||
|
||
//@ add-core-stubs | ||
//@ run-pass | ||
//@ should-fail |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
//! Auxiliary `minicore` prelude which stubs out `core` items for `no_core` tests that need to work | ||
//! in cross-compilation scenarios where no `core` is available (that don't want nor need to | ||
//! `-Zbuild-std`). | ||
//! | ||
//! # Important notes | ||
//! | ||
//! - `minicore` is **only** intended for `core` items, and the stubs should match the actual `core` | ||
//! items. | ||
//! | ||
//! # References | ||
//! | ||
//! This is partially adapted from `rustc_codegen_cranelift`: | ||
//! <https://github.com/rust-lang/rust/blob/c0b5cc9003f6464c11ae1c0662c6a7e06f6f5cab/compiler/rustc_codegen_cranelift/example/mini_core.rs>. | ||
// ignore-tidy-linelength | ||
|
||
#![feature(no_core, lang_items, rustc_attrs)] | ||
#![allow(unused, improper_ctypes_definitions, internal_features)] | ||
#![no_std] | ||
#![no_core] | ||
|
||
// `core` has some exotic `marker_impls!` macro for handling the with-generics cases, but for our | ||
// purposes, just use a simple macro_rules macro. | ||
macro_rules! impl_marker_trait { | ||
($Trait:ident => [$( $ty:ident ),* $(,)?] ) => { | ||
$( impl $Trait for $ty {} )* | ||
} | ||
} | ||
|
||
#[lang = "sized"] | ||
pub trait Sized {} | ||
|
||
#[lang = "legacy_receiver"] | ||
pub trait LegacyReceiver {} | ||
impl<T: ?Sized> LegacyReceiver for &T {} | ||
impl<T: ?Sized> LegacyReceiver for &mut T {} | ||
|
||
#[lang = "copy"] | ||
pub trait Copy: Sized {} | ||
|
||
impl_marker_trait!(Copy => [ bool, char, isize, usize, i8, i16, i32, i64, u8, u16, u32, u64 ]); | ||
impl<'a, T: ?Sized> Copy for &'a T {} | ||
impl<T: ?Sized> Copy for *const T {} | ||
impl<T: ?Sized> Copy for *mut T {} | ||
|
||
#[lang = "phantom_data"] | ||
pub struct PhantomData<T: ?Sized>; | ||
impl<T: ?Sized> Copy for PhantomData<T> {} | ||
|
||
pub enum Option<T> { | ||
None, | ||
Some(T), | ||
} | ||
impl<T: Copy> Copy for Option<T> {} | ||
|
||
pub enum Result<T, E> { | ||
Ok(T), | ||
Err(E), | ||
} | ||
impl<T: Copy, E: Copy> Copy for Result<T, E> {} | ||
|
||
#[lang = "manually_drop"] | ||
#[repr(transparent)] | ||
pub struct ManuallyDrop<T: ?Sized> { | ||
value: T, | ||
} | ||
impl<T: Copy + ?Sized> Copy for ManuallyDrop<T> {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can derive #[rustc_builtin_macro]
pub macro Copy($item:item) {
/* compiler built-in */
} and the same applies to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not make this change because I couldn't figure out how to make use of this, just kept manual |
||
|
||
#[lang = "unsafe_cell"] | ||
#[repr(transparent)] | ||
pub struct UnsafeCell<T: ?Sized> { | ||
value: T, | ||
} |
jieyouxu marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//! Basic smoke test for `minicore` test auxiliary. | ||
|
||
//@ add-core-stubs | ||
//@ compile-flags: --target=x86_64-unknown-linux-gnu | ||
//@ needs-llvm-components: x86 | ||
|
||
#![crate_type = "lib"] | ||
#![feature(no_core)] | ||
#![no_std] | ||
#![no_core] | ||
|
||
extern crate minicore; | ||
use minicore::*; | ||
|
||
struct Meow; | ||
impl Copy for Meow {} | ||
|
||
// CHECK-LABEL: meow | ||
#[no_mangle] | ||
fn meow() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remark: I don't like how convoluted the top-level runtest logic is, but intended for future compiletest cleanup PRs instead of this PR.