Skip to content

Commit 9d6f01a

Browse files
committed
use-minicore in tests/ui/abi/compatibility.rs as example
1 parent ba30572 commit 9d6f01a

File tree

1 file changed

+9
-121
lines changed

1 file changed

+9
-121
lines changed

tests/ui/abi/compatibility.rs

+9-121
Original file line numberDiff line numberDiff line change
@@ -58,135 +58,23 @@
5858
//@ revisions: nvptx64
5959
//@[nvptx64] compile-flags: --target nvptx64-nvidia-cuda
6060
//@[nvptx64] needs-llvm-components: nvptx
61-
#![feature(rustc_attrs, unsized_fn_params, transparent_unions)]
62-
#![cfg_attr(not(host), feature(no_core, lang_items), no_std, no_core)]
63-
#![allow(unused, improper_ctypes_definitions, internal_features)]
6461

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

70-
#[cfg(host)]
71-
use std::{
72-
any::Any, marker::PhantomData, mem::ManuallyDrop, num::NonZero, ptr::NonNull, rc::Rc, sync::Arc,
73-
};
74-
75-
/// To work cross-target this test must be no_core.
76-
/// This little prelude supplies what we need.
77-
#[cfg(not(host))]
78-
mod prelude {
79-
#[lang = "sized"]
80-
pub trait Sized {}
81-
82-
#[lang = "receiver"]
83-
pub trait Receiver {}
84-
impl<T: ?Sized> Receiver for &T {}
85-
impl<T: ?Sized> Receiver for &mut T {}
86-
87-
#[lang = "copy"]
88-
pub trait Copy: Sized {}
89-
impl Copy for i32 {}
90-
impl Copy for f32 {}
91-
impl<T: ?Sized> Copy for &T {}
92-
impl<T: ?Sized> Copy for *const T {}
93-
impl<T: ?Sized> Copy for *mut T {}
94-
95-
#[lang = "clone"]
96-
pub trait Clone: Sized {
97-
fn clone(&self) -> Self;
98-
}
99-
100-
#[lang = "phantom_data"]
101-
pub struct PhantomData<T: ?Sized>;
102-
impl<T: ?Sized> Copy for PhantomData<T> {}
103-
104-
#[lang = "unsafe_cell"]
105-
#[repr(transparent)]
106-
pub struct UnsafeCell<T: ?Sized> {
107-
value: T,
108-
}
109-
110-
pub trait Any: 'static {}
111-
112-
pub enum Option<T> {
113-
None,
114-
Some(T),
115-
}
116-
impl<T: Copy> Copy for Option<T> {}
117-
118-
pub enum Result<T, E> {
119-
Ok(T),
120-
Err(E),
121-
}
122-
impl<T: Copy, E: Copy> Copy for Result<T, E> {}
123-
124-
#[lang = "manually_drop"]
125-
#[repr(transparent)]
126-
pub struct ManuallyDrop<T: ?Sized> {
127-
value: T,
128-
}
129-
impl<T: Copy + ?Sized> Copy for ManuallyDrop<T> {}
67+
#![feature(no_core)]
68+
#![no_core]
69+
#![no_std]
13070

131-
#[repr(transparent)]
132-
#[rustc_layout_scalar_valid_range_start(1)]
133-
#[rustc_nonnull_optimization_guaranteed]
134-
pub struct NonNull<T: ?Sized> {
135-
pointer: *const T,
136-
}
137-
impl<T: ?Sized> Copy for NonNull<T> {}
138-
139-
#[repr(transparent)]
140-
#[rustc_layout_scalar_valid_range_start(1)]
141-
#[rustc_nonnull_optimization_guaranteed]
142-
pub struct NonZero<T>(T);
143-
144-
// This just stands in for a non-trivial type.
145-
pub struct Vec<T> {
146-
ptr: NonNull<T>,
147-
cap: usize,
148-
len: usize,
149-
}
150-
151-
pub struct Unique<T: ?Sized> {
152-
pub pointer: NonNull<T>,
153-
pub _marker: PhantomData<T>,
154-
}
155-
156-
#[lang = "global_alloc_ty"]
157-
pub struct Global;
158-
159-
#[lang = "owned_box"]
160-
pub struct Box<T: ?Sized, A = Global>(Unique<T>, A);
161-
162-
#[repr(C)]
163-
struct RcBox<T: ?Sized> {
164-
strong: UnsafeCell<usize>,
165-
weak: UnsafeCell<usize>,
166-
value: T,
167-
}
168-
pub struct Rc<T: ?Sized, A = Global> {
169-
ptr: NonNull<RcBox<T>>,
170-
phantom: PhantomData<RcBox<T>>,
171-
alloc: A,
172-
}
71+
#![feature(unsized_fn_params, transparent_unions, rustc_attrs)]
72+
#![allow(unused, improper_ctypes_definitions, internal_features)]
17373

174-
#[repr(C, align(8))]
175-
struct AtomicUsize(usize);
176-
#[repr(C)]
177-
struct ArcInner<T: ?Sized> {
178-
strong: AtomicUsize,
179-
weak: AtomicUsize,
180-
data: T,
181-
}
182-
pub struct Arc<T: ?Sized, A = Global> {
183-
ptr: NonNull<ArcInner<T>>,
184-
phantom: PhantomData<ArcInner<T>>,
185-
alloc: A,
186-
}
187-
}
188-
#[cfg(not(host))]
189-
use prelude::*;
74+
//@ use-minicore
75+
extern crate minicore;
76+
use minicore as _;
77+
use minicore::*;
19078

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

0 commit comments

Comments
 (0)