Skip to content

Commit 4e56a84

Browse files
committed
tests: use minicore in tests/ui/abi/compatibility.rs as an example
1 parent 3843593 commit 4e56a84

File tree

2 files changed

+26
-75
lines changed

2 files changed

+26
-75
lines changed

tests/auxiliary/minicore.rs

+14-19
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,26 @@
1818
#![no_std]
1919
#![no_core]
2020

21+
// `core` has some exotic `marker_impls!` macro for handling the with-generics cases, but for our
22+
// purposes, just use a simple macro_rules macro.
23+
macro_rules! impl_marker_trait {
24+
($Trait:ident => [$( $ty:ident ),* $(,)?] ) => {
25+
$( impl $Trait for $ty {} )*
26+
}
27+
}
28+
2129
#[lang = "sized"]
2230
pub trait Sized {}
2331

24-
#[lang = "receiver"]
25-
pub trait Receiver {}
26-
impl<T: ?Sized> Receiver for &T {}
27-
impl<T: ?Sized> Receiver for &mut T {}
32+
#[lang = "legacy_receiver"]
33+
pub trait LegacyReceiver {}
34+
impl<T: ?Sized> LegacyReceiver for &T {}
35+
impl<T: ?Sized> LegacyReceiver for &mut T {}
2836

2937
#[lang = "copy"]
30-
pub trait Copy {}
38+
pub trait Copy: Sized {}
3139

32-
impl Copy for bool {}
33-
impl Copy for u8 {}
34-
impl Copy for u16 {}
35-
impl Copy for u32 {}
36-
impl Copy for u64 {}
37-
impl Copy for u128 {}
38-
impl Copy for usize {}
39-
impl Copy for i8 {}
40-
impl Copy for i16 {}
41-
impl Copy for i32 {}
42-
impl Copy for isize {}
43-
impl Copy for f32 {}
44-
impl Copy for f64 {}
45-
impl Copy for char {}
40+
impl_marker_trait!(Copy => [ bool, char, isize, usize, i8, i16, i32, i64, u8, u16, u32, u64 ]);
4641
impl<'a, T: ?Sized> Copy for &'a T {}
4742
impl<T: ?Sized> Copy for *const T {}
4843
impl<T: ?Sized> Copy for *mut T {}

tests/ui/abi/compatibility.rs

+12-56
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//@ check-pass
2+
//@ add-core-stubs
23
//@ revisions: host
34
//@ revisions: i686
45
//@[i686] compile-flags: --target i686-unknown-linux-gnu
@@ -58,76 +59,32 @@
5859
//@ revisions: nvptx64
5960
//@[nvptx64] compile-flags: --target nvptx64-nvidia-cuda
6061
//@[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)]
62+
#![feature(no_core, rustc_attrs, lang_items)]
63+
#![feature(unsized_fn_params, transparent_unions)]
64+
#![no_std]
65+
#![no_core]
6366
#![allow(unused, improper_ctypes_definitions, internal_features)]
6467

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

70-
#[cfg(host)]
71-
use std::{
72-
any::Any, marker::PhantomData, mem::ManuallyDrop, num::NonZero, ptr::NonNull, rc::Rc, sync::Arc,
73-
};
73+
extern crate minicore;
74+
use minicore::*;
7475

75-
/// To work cross-target this test must be no_core.
76-
/// This little prelude supplies what we need.
77-
#[cfg(not(host))]
76+
/// To work cross-target this test must be no_core. This little prelude supplies what we need.
77+
///
78+
/// Note that `minicore` provides a very minimal subset of `core` items (not yet complete). This
79+
/// prelude contains `alloc` and non-`core` (but in `std`) items that minicore does not stub out.
7880
mod prelude {
79-
#[lang = "sized"]
80-
pub trait Sized {}
81-
82-
#[lang = "legacy_receiver"]
83-
pub trait LegacyReceiver {}
84-
impl<T: ?Sized> LegacyReceiver for &T {}
85-
impl<T: ?Sized> LegacyReceiver 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 {}
81+
use minicore::*;
9482

9583
#[lang = "clone"]
9684
pub trait Clone: Sized {
9785
fn clone(&self) -> Self;
9886
}
9987

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> {}
130-
13188
#[repr(transparent)]
13289
#[rustc_layout_scalar_valid_range_start(1)]
13390
#[rustc_nonnull_optimization_guaranteed]
@@ -185,7 +142,6 @@ mod prelude {
185142
alloc: A,
186143
}
187144
}
188-
#[cfg(not(host))]
189145
use prelude::*;
190146

191147
macro_rules! test_abi_compatible {

0 commit comments

Comments
 (0)