Skip to content

Commit

Permalink
use-minicore in tests/ui/abi/compatibility.rs as example
Browse files Browse the repository at this point in the history
  • Loading branch information
jieyouxu committed Sep 22, 2024
1 parent ba30572 commit 9d6f01a
Showing 1 changed file with 9 additions and 121 deletions.
130 changes: 9 additions & 121 deletions tests/ui/abi/compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,135 +58,23 @@
//@ revisions: nvptx64
//@[nvptx64] compile-flags: --target nvptx64-nvidia-cuda
//@[nvptx64] needs-llvm-components: nvptx
#![feature(rustc_attrs, unsized_fn_params, transparent_unions)]
#![cfg_attr(not(host), feature(no_core, lang_items), no_std, no_core)]
#![allow(unused, improper_ctypes_definitions, internal_features)]

// FIXME: some targets are broken in various ways.
// Hence there are `cfg` throughout this test to disable parts of it on those targets.
// sparc64: https://github.com/rust-lang/rust/issues/115336
// mips64: https://github.com/rust-lang/rust/issues/115404

#[cfg(host)]
use std::{
any::Any, marker::PhantomData, mem::ManuallyDrop, num::NonZero, ptr::NonNull, rc::Rc, sync::Arc,
};

/// To work cross-target this test must be no_core.
/// This little prelude supplies what we need.
#[cfg(not(host))]
mod prelude {
#[lang = "sized"]
pub trait Sized {}

#[lang = "receiver"]
pub trait Receiver {}
impl<T: ?Sized> Receiver for &T {}
impl<T: ?Sized> Receiver 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"]
pub trait Clone: Sized {
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> {}
#![feature(no_core)]
#![no_core]
#![no_std]

#[repr(transparent)]
#[rustc_layout_scalar_valid_range_start(1)]
#[rustc_nonnull_optimization_guaranteed]
pub struct NonNull<T: ?Sized> {
pointer: *const T,
}
impl<T: ?Sized> Copy for NonNull<T> {}

#[repr(transparent)]
#[rustc_layout_scalar_valid_range_start(1)]
#[rustc_nonnull_optimization_guaranteed]
pub struct NonZero<T>(T);

// This just stands in for a non-trivial type.
pub struct Vec<T> {
ptr: NonNull<T>,
cap: usize,
len: usize,
}

pub struct Unique<T: ?Sized> {
pub pointer: NonNull<T>,
pub _marker: PhantomData<T>,
}

#[lang = "global_alloc_ty"]
pub struct Global;

#[lang = "owned_box"]
pub struct Box<T: ?Sized, A = Global>(Unique<T>, A);

#[repr(C)]
struct RcBox<T: ?Sized> {
strong: UnsafeCell<usize>,
weak: UnsafeCell<usize>,
value: T,
}
pub struct Rc<T: ?Sized, A = Global> {
ptr: NonNull<RcBox<T>>,
phantom: PhantomData<RcBox<T>>,
alloc: A,
}
#![feature(unsized_fn_params, transparent_unions, rustc_attrs)]
#![allow(unused, improper_ctypes_definitions, internal_features)]

#[repr(C, align(8))]
struct AtomicUsize(usize);
#[repr(C)]
struct ArcInner<T: ?Sized> {
strong: AtomicUsize,
weak: AtomicUsize,
data: T,
}
pub struct Arc<T: ?Sized, A = Global> {
ptr: NonNull<ArcInner<T>>,
phantom: PhantomData<ArcInner<T>>,
alloc: A,
}
}
#[cfg(not(host))]
use prelude::*;
//@ use-minicore
extern crate minicore;
use minicore as _;
use minicore::*;

macro_rules! test_abi_compatible {
($name:ident, $t1:ty, $t2:ty) => {
Expand Down

0 comments on commit 9d6f01a

Please sign in to comment.