Skip to content

Commit daf4f61

Browse files
committed
cranelift/gcc: {Meta,Pointee,}Sized in minicore
As in many previous commits, adding the new traits to minicore, but this time for cranelift and gcc.
1 parent f4511bb commit daf4f61

File tree

2 files changed

+72
-60
lines changed

2 files changed

+72
-60
lines changed

compiler/rustc_codegen_cranelift/example/mini_core.rs

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@
1414
#![no_core]
1515
#![allow(dead_code, internal_features, ambiguous_wide_pointer_comparisons)]
1616

17+
#[lang = "pointee_sized"]
18+
pub trait PointeeSized {}
19+
20+
#[lang = "meta_sized"]
21+
pub trait MetaSized: PointeeSized {}
22+
1723
#[lang = "sized"]
18-
pub trait Sized {}
24+
pub trait Sized: MetaSized {}
1925

2026
#[lang = "destruct"]
2127
pub trait Destruct {}
@@ -24,35 +30,35 @@ pub trait Destruct {}
2430
pub trait Tuple {}
2531

2632
#[lang = "unsize"]
27-
pub trait Unsize<T: ?Sized> {}
33+
pub trait Unsize<T: PointeeSized>: PointeeSized {}
2834

2935
#[lang = "coerce_unsized"]
3036
pub trait CoerceUnsized<T> {}
3137

32-
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
33-
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
34-
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
35-
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
38+
impl<'a, 'b: 'a, T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<&'a U> for &'b T {}
39+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<&'a mut U> for &'a mut T {}
40+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<*const U> for *const T {}
41+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<*mut U> for *mut T {}
3642

3743
#[lang = "dispatch_from_dyn"]
3844
pub trait DispatchFromDyn<T> {}
3945

4046
// &T -> &U
41-
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
47+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<&'a U> for &'a T {}
4248
// &mut T -> &mut U
43-
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
49+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<&'a mut U> for &'a mut T {}
4450
// *const T -> *const U
45-
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
51+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<*const U> for *const T {}
4652
// *mut T -> *mut U
47-
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
48-
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U>> for Box<T> {}
53+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<*mut U> for *mut T {}
54+
impl<T: MetaSized + Unsize<U>, U: MetaSized> DispatchFromDyn<Box<U>> for Box<T> {}
4955

5056
#[lang = "legacy_receiver"]
5157
pub trait LegacyReceiver {}
5258

53-
impl<T: ?Sized> LegacyReceiver for &T {}
54-
impl<T: ?Sized> LegacyReceiver for &mut T {}
55-
impl<T: ?Sized> LegacyReceiver for Box<T> {}
59+
impl<T: PointeeSized> LegacyReceiver for &T {}
60+
impl<T: PointeeSized> LegacyReceiver for &mut T {}
61+
impl<T: MetaSized> LegacyReceiver for Box<T> {}
5662

5763
#[lang = "copy"]
5864
pub trait Copy {}
@@ -74,9 +80,9 @@ impl Copy for isize {}
7480
impl Copy for f32 {}
7581
impl Copy for f64 {}
7682
impl Copy for char {}
77-
impl<'a, T: ?Sized> Copy for &'a T {}
78-
impl<T: ?Sized> Copy for *const T {}
79-
impl<T: ?Sized> Copy for *mut T {}
83+
impl<'a, T: PointeeSized> Copy for &'a T {}
84+
impl<T: PointeeSized> Copy for *const T {}
85+
impl<T: PointeeSized> Copy for *mut T {}
8086
impl<T: Copy> Copy for Option<T> {}
8187

8288
#[lang = "sync"]
@@ -94,17 +100,17 @@ unsafe impl Sync for i32 {}
94100
unsafe impl Sync for isize {}
95101
unsafe impl Sync for char {}
96102
unsafe impl Sync for f32 {}
97-
unsafe impl<'a, T: ?Sized> Sync for &'a T {}
103+
unsafe impl<'a, T: PointeeSized> Sync for &'a T {}
98104
unsafe impl<T: Sync, const N: usize> Sync for [T; N] {}
99105

100106
#[lang = "freeze"]
101107
unsafe auto trait Freeze {}
102108

103-
unsafe impl<T: ?Sized> Freeze for PhantomData<T> {}
104-
unsafe impl<T: ?Sized> Freeze for *const T {}
105-
unsafe impl<T: ?Sized> Freeze for *mut T {}
106-
unsafe impl<T: ?Sized> Freeze for &T {}
107-
unsafe impl<T: ?Sized> Freeze for &mut T {}
109+
unsafe impl<T: PointeeSized> Freeze for PhantomData<T> {}
110+
unsafe impl<T: PointeeSized> Freeze for *const T {}
111+
unsafe impl<T: PointeeSized> Freeze for *mut T {}
112+
unsafe impl<T: PointeeSized> Freeze for &T {}
113+
unsafe impl<T: PointeeSized> Freeze for &mut T {}
108114

109115
#[lang = "structural_peq"]
110116
pub trait StructuralPartialEq {}
@@ -443,7 +449,7 @@ pub enum Option<T> {
443449
pub use Option::*;
444450

445451
#[lang = "phantom_data"]
446-
pub struct PhantomData<T: ?Sized>;
452+
pub struct PhantomData<T: PointeeSized>;
447453

448454
#[lang = "fn_once"]
449455
#[rustc_paren_sugar]
@@ -564,18 +570,18 @@ pub trait Deref {
564570
#[repr(transparent)]
565571
#[rustc_layout_scalar_valid_range_start(1)]
566572
#[rustc_nonnull_optimization_guaranteed]
567-
pub struct NonNull<T: ?Sized>(pub *const T);
573+
pub struct NonNull<T: PointeeSized>(pub *const T);
568574

569-
impl<T: ?Sized, U: ?Sized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
570-
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
575+
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
576+
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
571577

572-
pub struct Unique<T: ?Sized> {
578+
pub struct Unique<T: PointeeSized> {
573579
pub pointer: NonNull<T>,
574580
pub _marker: PhantomData<T>,
575581
}
576582

577-
impl<T: ?Sized, U: ?Sized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
578-
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
583+
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
584+
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
579585

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

compiler/rustc_codegen_gcc/example/mini_core.rs

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ unsafe extern "C" fn _Unwind_Resume() {
1919
intrinsics::unreachable();
2020
}
2121

22+
#[lang = "pointee_sized"]
23+
pub trait PointeeSized {}
24+
25+
#[lang = "meta_sized"]
26+
pub trait MetaSized: PointeeSized {}
27+
2228
#[lang = "sized"]
23-
pub trait Sized {}
29+
pub trait Sized: MetaSized {}
2430

2531
#[lang = "destruct"]
2632
pub trait Destruct {}
@@ -29,35 +35,35 @@ pub trait Destruct {}
2935
pub trait Tuple {}
3036

3137
#[lang = "unsize"]
32-
pub trait Unsize<T: ?Sized> {}
38+
pub trait Unsize<T: PointeeSized>: PointeeSized {}
3339

3440
#[lang = "coerce_unsized"]
3541
pub trait CoerceUnsized<T> {}
3642

37-
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
38-
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
39-
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
40-
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
43+
impl<'a, 'b: 'a, T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<&'a U> for &'b T {}
44+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<&'a mut U> for &'a mut T {}
45+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<*const U> for *const T {}
46+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<*mut U> for *mut T {}
4147

4248
#[lang = "dispatch_from_dyn"]
4349
pub trait DispatchFromDyn<T> {}
4450

4551
// &T -> &U
46-
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
52+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<&'a U> for &'a T {}
4753
// &mut T -> &mut U
48-
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
54+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<&'a mut U> for &'a mut T {}
4955
// *const T -> *const U
50-
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
56+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<*const U> for *const T {}
5157
// *mut T -> *mut U
52-
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
53-
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U, ()>> for Box<T, ()> {}
58+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<*mut U> for *mut T {}
59+
impl<T: MetaSized + Unsize<U>, U: MetaSized> DispatchFromDyn<Box<U, ()>> for Box<T, ()> {}
5460

5561
#[lang = "legacy_receiver"]
5662
pub trait LegacyReceiver {}
5763

58-
impl<T: ?Sized> LegacyReceiver for &T {}
59-
impl<T: ?Sized> LegacyReceiver for &mut T {}
60-
impl<T: ?Sized, A: Allocator> LegacyReceiver for Box<T, A> {}
64+
impl<T: PointeeSized> LegacyReceiver for &T {}
65+
impl<T: PointeeSized> LegacyReceiver for &mut T {}
66+
impl<T: MetaSized> LegacyReceiver for Box<T> {}
6167

6268
#[lang = "receiver"]
6369
trait Receiver {}
@@ -84,9 +90,9 @@ impl Copy for i128 {}
8490
impl Copy for f32 {}
8591
impl Copy for f64 {}
8692
impl Copy for char {}
87-
impl<'a, T: ?Sized> Copy for &'a T {}
88-
impl<T: ?Sized> Copy for *const T {}
89-
impl<T: ?Sized> Copy for *mut T {}
93+
impl<'a, T: PointeeSized> Copy for &'a T {}
94+
impl<T: PointeeSized> Copy for *const T {}
95+
impl<T: PointeeSized> Copy for *mut T {}
9096

9197
#[lang = "sync"]
9298
pub unsafe trait Sync {}
@@ -102,17 +108,17 @@ unsafe impl Sync for i16 {}
102108
unsafe impl Sync for i32 {}
103109
unsafe impl Sync for isize {}
104110
unsafe impl Sync for char {}
105-
unsafe impl<'a, T: ?Sized> Sync for &'a T {}
111+
unsafe impl<'a, T: PointeeSized> Sync for &'a T {}
106112
unsafe impl Sync for [u8; 16] {}
107113

108114
#[lang = "freeze"]
109115
unsafe auto trait Freeze {}
110116

111-
unsafe impl<T: ?Sized> Freeze for PhantomData<T> {}
112-
unsafe impl<T: ?Sized> Freeze for *const T {}
113-
unsafe impl<T: ?Sized> Freeze for *mut T {}
114-
unsafe impl<T: ?Sized> Freeze for &T {}
115-
unsafe impl<T: ?Sized> Freeze for &mut T {}
117+
unsafe impl<T: PointeeSized> Freeze for PhantomData<T> {}
118+
unsafe impl<T: PointeeSized> Freeze for *const T {}
119+
unsafe impl<T: PointeeSized> Freeze for *mut T {}
120+
unsafe impl<T: PointeeSized> Freeze for &T {}
121+
unsafe impl<T: PointeeSized> Freeze for &mut T {}
116122

117123
#[lang = "structural_peq"]
118124
pub trait StructuralPartialEq {}
@@ -456,7 +462,7 @@ pub enum Option<T> {
456462
pub use Option::*;
457463

458464
#[lang = "phantom_data"]
459-
pub struct PhantomData<T: ?Sized>;
465+
pub struct PhantomData<T: PointeeSized>;
460466

461467
#[lang = "fn_once"]
462468
#[rustc_paren_sugar]
@@ -576,18 +582,18 @@ impl Allocator for Global {}
576582
#[repr(transparent)]
577583
#[rustc_layout_scalar_valid_range_start(1)]
578584
#[rustc_nonnull_optimization_guaranteed]
579-
pub struct NonNull<T: ?Sized>(pub *const T);
585+
pub struct NonNull<T: PointeeSized>(pub *const T);
580586

581-
impl<T: ?Sized, U: ?Sized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
582-
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
587+
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
588+
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
583589

584-
pub struct Unique<T: ?Sized> {
590+
pub struct Unique<T: PointeeSized> {
585591
pub pointer: NonNull<T>,
586592
pub _marker: PhantomData<T>,
587593
}
588594

589-
impl<T: ?Sized, U: ?Sized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
590-
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
595+
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
596+
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
591597

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

0 commit comments

Comments
 (0)