Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 45a9ef1

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 76ed74b commit 45a9ef1

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]
@@ -546,18 +552,18 @@ pub trait Deref {
546552
#[repr(transparent)]
547553
#[rustc_layout_scalar_valid_range_start(1)]
548554
#[rustc_nonnull_optimization_guaranteed]
549-
pub struct NonNull<T: ?Sized>(pub *const T);
555+
pub struct NonNull<T: PointeeSized>(pub *const T);
550556

551-
impl<T: ?Sized, U: ?Sized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
552-
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
557+
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
558+
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
553559

554-
pub struct Unique<T: ?Sized> {
560+
pub struct Unique<T: PointeeSized> {
555561
pub pointer: NonNull<T>,
556562
pub _marker: PhantomData<T>,
557563
}
558564

559-
impl<T: ?Sized, U: ?Sized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
560-
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
565+
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
566+
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
561567

562568
#[lang = "global_alloc_ty"]
563569
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
@@ -11,8 +11,14 @@ unsafe extern "C" fn _Unwind_Resume() {
1111
intrinsics::unreachable();
1212
}
1313

14+
#[lang = "pointee_sized"]
15+
pub trait PointeeSized {}
16+
17+
#[lang = "meta_sized"]
18+
pub trait MetaSized: PointeeSized {}
19+
1420
#[lang = "sized"]
15-
pub trait Sized {}
21+
pub trait Sized: MetaSized {}
1622

1723
#[lang = "destruct"]
1824
pub trait Destruct {}
@@ -21,35 +27,35 @@ pub trait Destruct {}
2127
pub trait Tuple {}
2228

2329
#[lang = "unsize"]
24-
pub trait Unsize<T: ?Sized> {}
30+
pub trait Unsize<T: PointeeSized>: PointeeSized {}
2531

2632
#[lang = "coerce_unsized"]
2733
pub trait CoerceUnsized<T> {}
2834

29-
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
30-
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
31-
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
32-
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
35+
impl<'a, 'b: 'a, T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<&'a U> for &'b T {}
36+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<&'a mut U> for &'a mut T {}
37+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<*const U> for *const T {}
38+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<*mut U> for *mut T {}
3339

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

3743
// &T -> &U
38-
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
44+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<&'a U> for &'a T {}
3945
// &mut T -> &mut U
40-
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
46+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<&'a mut U> for &'a mut T {}
4147
// *const T -> *const U
42-
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
48+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<*const U> for *const T {}
4349
// *mut T -> *mut U
44-
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
45-
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U, ()>> for Box<T, ()> {}
50+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<*mut U> for *mut T {}
51+
impl<T: MetaSized + Unsize<U>, U: MetaSized> DispatchFromDyn<Box<U, ()>> for Box<T, ()> {}
4652

4753
#[lang = "legacy_receiver"]
4854
pub trait LegacyReceiver {}
4955

50-
impl<T: ?Sized> LegacyReceiver for &T {}
51-
impl<T: ?Sized> LegacyReceiver for &mut T {}
52-
impl<T: ?Sized, A: Allocator> LegacyReceiver for Box<T, A> {}
56+
impl<T: PointeeSized> LegacyReceiver for &T {}
57+
impl<T: PointeeSized> LegacyReceiver for &mut T {}
58+
impl<T: MetaSized> LegacyReceiver for Box<T> {}
5359

5460
#[lang = "receiver"]
5561
trait Receiver {
@@ -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

8187
#[lang = "sync"]
8288
pub unsafe trait Sync {}
@@ -92,17 +98,17 @@ unsafe impl Sync for i16 {}
9298
unsafe impl Sync for i32 {}
9399
unsafe impl Sync for isize {}
94100
unsafe impl Sync for char {}
95-
unsafe impl<'a, T: ?Sized> Sync for &'a T {}
101+
unsafe impl<'a, T: PointeeSized> Sync for &'a T {}
96102
unsafe impl Sync for [u8; 16] {}
97103

98104
#[lang = "freeze"]
99105
unsafe auto trait Freeze {}
100106

101-
unsafe impl<T: ?Sized> Freeze for PhantomData<T> {}
102-
unsafe impl<T: ?Sized> Freeze for *const T {}
103-
unsafe impl<T: ?Sized> Freeze for *mut T {}
104-
unsafe impl<T: ?Sized> Freeze for &T {}
105-
unsafe impl<T: ?Sized> Freeze for &mut T {}
107+
unsafe impl<T: PointeeSized> Freeze for PhantomData<T> {}
108+
unsafe impl<T: PointeeSized> Freeze for *const T {}
109+
unsafe impl<T: PointeeSized> Freeze for *mut T {}
110+
unsafe impl<T: PointeeSized> Freeze for &T {}
111+
unsafe impl<T: PointeeSized> Freeze for &mut T {}
106112

107113
#[lang = "structural_peq"]
108114
pub trait StructuralPartialEq {}
@@ -447,7 +453,7 @@ pub enum Option<T> {
447453
pub use Option::*;
448454

449455
#[lang = "phantom_data"]
450-
pub struct PhantomData<T: ?Sized>;
456+
pub struct PhantomData<T: PointeeSized>;
451457

452458
#[lang = "fn_once"]
453459
#[rustc_paren_sugar]
@@ -564,18 +570,18 @@ impl Allocator for Global {}
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 = "owned_box"]
581587
pub struct Box<T: ?Sized, A: Allocator = Global>(Unique<T>, A);

0 commit comments

Comments
 (0)