tests: use minicore in tests/ui/abi/compatibility.rs
as an example
This commit is contained in:
parent
0bbe07e8ff
commit
adb6d4752f
@ -18,31 +18,26 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_core]
|
#![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"]
|
#[lang = "sized"]
|
||||||
pub trait Sized {}
|
pub trait Sized {}
|
||||||
|
|
||||||
#[lang = "receiver"]
|
#[lang = "legacy_receiver"]
|
||||||
pub trait Receiver {}
|
pub trait LegacyReceiver {}
|
||||||
impl<T: ?Sized> Receiver for &T {}
|
impl<T: ?Sized> LegacyReceiver for &T {}
|
||||||
impl<T: ?Sized> Receiver for &mut T {}
|
impl<T: ?Sized> LegacyReceiver for &mut T {}
|
||||||
|
|
||||||
#[lang = "copy"]
|
#[lang = "copy"]
|
||||||
pub trait Copy {}
|
pub trait Copy: Sized {}
|
||||||
|
|
||||||
impl Copy for bool {}
|
impl_marker_trait!(Copy => [ bool, char, isize, usize, i8, i16, i32, i64, u8, u16, u32, u64 ]);
|
||||||
impl Copy for u8 {}
|
|
||||||
impl Copy for u16 {}
|
|
||||||
impl Copy for u32 {}
|
|
||||||
impl Copy for u64 {}
|
|
||||||
impl Copy for u128 {}
|
|
||||||
impl Copy for usize {}
|
|
||||||
impl Copy for i8 {}
|
|
||||||
impl Copy for i16 {}
|
|
||||||
impl Copy for i32 {}
|
|
||||||
impl Copy for isize {}
|
|
||||||
impl Copy for f32 {}
|
|
||||||
impl Copy for f64 {}
|
|
||||||
impl Copy for char {}
|
|
||||||
impl<'a, T: ?Sized> Copy for &'a T {}
|
impl<'a, T: ?Sized> Copy for &'a T {}
|
||||||
impl<T: ?Sized> Copy for *const T {}
|
impl<T: ?Sized> Copy for *const T {}
|
||||||
impl<T: ?Sized> Copy for *mut T {}
|
impl<T: ?Sized> Copy for *mut T {}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
//@ check-pass
|
//@ check-pass
|
||||||
|
//@ add-core-stubs
|
||||||
//@ revisions: host
|
//@ revisions: host
|
||||||
//@ revisions: i686
|
//@ revisions: i686
|
||||||
//@[i686] compile-flags: --target i686-unknown-linux-gnu
|
//@[i686] compile-flags: --target i686-unknown-linux-gnu
|
||||||
@ -58,8 +59,10 @@
|
|||||||
//@ revisions: nvptx64
|
//@ revisions: nvptx64
|
||||||
//@[nvptx64] compile-flags: --target nvptx64-nvidia-cuda
|
//@[nvptx64] compile-flags: --target nvptx64-nvidia-cuda
|
||||||
//@[nvptx64] needs-llvm-components: nvptx
|
//@[nvptx64] needs-llvm-components: nvptx
|
||||||
#![feature(rustc_attrs, unsized_fn_params, transparent_unions)]
|
#![feature(no_core, rustc_attrs, lang_items)]
|
||||||
#![cfg_attr(not(host), feature(no_core, lang_items), no_std, no_core)]
|
#![feature(unsized_fn_params, transparent_unions)]
|
||||||
|
#![no_std]
|
||||||
|
#![no_core]
|
||||||
#![allow(unused, improper_ctypes_definitions, internal_features)]
|
#![allow(unused, improper_ctypes_definitions, internal_features)]
|
||||||
|
|
||||||
// FIXME: some targets are broken in various ways.
|
// FIXME: some targets are broken in various ways.
|
||||||
@ -67,67 +70,24 @@
|
|||||||
// sparc64: https://github.com/rust-lang/rust/issues/115336
|
// sparc64: https://github.com/rust-lang/rust/issues/115336
|
||||||
// mips64: https://github.com/rust-lang/rust/issues/115404
|
// mips64: https://github.com/rust-lang/rust/issues/115404
|
||||||
|
|
||||||
#[cfg(host)]
|
extern crate minicore;
|
||||||
use std::{
|
use minicore::*;
|
||||||
any::Any, marker::PhantomData, mem::ManuallyDrop, num::NonZero, ptr::NonNull, rc::Rc, sync::Arc,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// To work cross-target this test must be no_core.
|
/// To work cross-target this test must be no_core. This little prelude supplies what we need.
|
||||||
/// This little prelude supplies what we need.
|
///
|
||||||
#[cfg(not(host))]
|
/// Note that `minicore` provides a very minimal subset of `core` items (not yet complete). This
|
||||||
|
/// prelude contains `alloc` and non-`core` (but in `std`) items that minicore does not stub out.
|
||||||
mod prelude {
|
mod prelude {
|
||||||
#[lang = "sized"]
|
use minicore::*;
|
||||||
pub trait Sized {}
|
|
||||||
|
|
||||||
#[lang = "legacy_receiver"]
|
// Trait stub, no `type_id` method.
|
||||||
pub trait LegacyReceiver {}
|
pub trait Any: 'static {}
|
||||||
impl<T: ?Sized> LegacyReceiver for &T {}
|
|
||||||
impl<T: ?Sized> LegacyReceiver for &mut T {}
|
|
||||||
|
|
||||||
#[lang = "copy"]
|
|
||||||
pub trait Copy: Sized {}
|
|
||||||
impl Copy for i32 {}
|
|
||||||
impl Copy for f32 {}
|
|
||||||
impl<T: ?Sized> Copy for &T {}
|
|
||||||
impl<T: ?Sized> Copy for *const T {}
|
|
||||||
impl<T: ?Sized> Copy for *mut T {}
|
|
||||||
|
|
||||||
#[lang = "clone"]
|
#[lang = "clone"]
|
||||||
pub trait Clone: Sized {
|
pub trait Clone: Sized {
|
||||||
fn clone(&self) -> Self;
|
fn clone(&self) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[lang = "phantom_data"]
|
|
||||||
pub struct PhantomData<T: ?Sized>;
|
|
||||||
impl<T: ?Sized> Copy for PhantomData<T> {}
|
|
||||||
|
|
||||||
#[lang = "unsafe_cell"]
|
|
||||||
#[repr(transparent)]
|
|
||||||
pub struct UnsafeCell<T: ?Sized> {
|
|
||||||
value: T,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait Any: 'static {}
|
|
||||||
|
|
||||||
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> {}
|
|
||||||
|
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
#[rustc_layout_scalar_valid_range_start(1)]
|
#[rustc_layout_scalar_valid_range_start(1)]
|
||||||
#[rustc_nonnull_optimization_guaranteed]
|
#[rustc_nonnull_optimization_guaranteed]
|
||||||
@ -185,7 +145,6 @@ pub struct Arc<T: ?Sized, A = Global> {
|
|||||||
alloc: A,
|
alloc: A,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(not(host))]
|
|
||||||
use prelude::*;
|
use prelude::*;
|
||||||
|
|
||||||
macro_rules! test_abi_compatible {
|
macro_rules! test_abi_compatible {
|
||||||
|
Loading…
Reference in New Issue
Block a user