Skip to content

Commit 2beed43

Browse files
committed
cranelift/gcc: add sizedness traits to minicore
As in many previous commits, adding the new traits and constness to the minicore.
1 parent 86512cb commit 2beed43

File tree

2 files changed

+79
-62
lines changed

2 files changed

+79
-62
lines changed

compiler/rustc_codegen_cranelift/example/mini_core.rs

+40-31
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,22 @@
99
transparent_unions,
1010
auto_traits,
1111
freeze_impls,
12-
thread_local
12+
thread_local,
13+
const_trait_impl
1314
)]
1415
#![no_core]
1516
#![allow(dead_code, internal_features, ambiguous_wide_pointer_comparisons)]
1617

18+
#[lang = "pointeesized"]
19+
pub trait PointeeSized {}
20+
21+
#[lang = "metasized"]
22+
#[const_trait]
23+
pub trait MetaSized: PointeeSized {}
24+
1725
#[lang = "sized"]
18-
pub trait Sized {}
26+
#[const_trait]
27+
pub trait Sized: MetaSized {}
1928

2029
#[lang = "destruct"]
2130
pub trait Destruct {}
@@ -24,35 +33,35 @@ pub trait Destruct {}
2433
pub trait Tuple {}
2534

2635
#[lang = "unsize"]
27-
pub trait Unsize<T: ?Sized> {}
36+
pub trait Unsize<T: PointeeSized>: PointeeSized {}
2837

2938
#[lang = "coerce_unsized"]
3039
pub trait CoerceUnsized<T> {}
3140

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 {}
41+
impl<'a, 'b: 'a, T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<&'a U> for &'b T {}
42+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<&'a mut U> for &'a mut T {}
43+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<*const U> for *const T {}
44+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<*mut U> for *mut T {}
3645

3746
#[lang = "dispatch_from_dyn"]
3847
pub trait DispatchFromDyn<T> {}
3948

4049
// &T -> &U
41-
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
50+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<&'a U> for &'a T {}
4251
// &mut T -> &mut U
43-
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
52+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<&'a mut U> for &'a mut T {}
4453
// *const T -> *const U
45-
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
54+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<*const U> for *const T {}
4655
// *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> {}
56+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<*mut U> for *mut T {}
57+
impl<T: MetaSized + Unsize<U>, U: MetaSized> DispatchFromDyn<Box<U>> for Box<T> {}
4958

5059
#[lang = "legacy_receiver"]
5160
pub trait LegacyReceiver {}
5261

53-
impl<T: ?Sized> LegacyReceiver for &T {}
54-
impl<T: ?Sized> LegacyReceiver for &mut T {}
55-
impl<T: ?Sized> LegacyReceiver for Box<T> {}
62+
impl<T: PointeeSized> LegacyReceiver for &T {}
63+
impl<T: PointeeSized> LegacyReceiver for &mut T {}
64+
impl<T: MetaSized> LegacyReceiver for Box<T> {}
5665

5766
#[lang = "copy"]
5867
pub trait Copy {}
@@ -74,9 +83,9 @@ impl Copy for isize {}
7483
impl Copy for f32 {}
7584
impl Copy for f64 {}
7685
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 {}
86+
impl<'a, T: PointeeSized> Copy for &'a T {}
87+
impl<T: PointeeSized> Copy for *const T {}
88+
impl<T: PointeeSized> Copy for *mut T {}
8089
impl<T: Copy> Copy for Option<T> {}
8190

8291
#[lang = "sync"]
@@ -94,17 +103,17 @@ unsafe impl Sync for i32 {}
94103
unsafe impl Sync for isize {}
95104
unsafe impl Sync for char {}
96105
unsafe impl Sync for f32 {}
97-
unsafe impl<'a, T: ?Sized> Sync for &'a T {}
106+
unsafe impl<'a, T: PointeeSized> Sync for &'a T {}
98107
unsafe impl<T: Sync, const N: usize> Sync for [T; N] {}
99108

100109
#[lang = "freeze"]
101110
unsafe auto trait Freeze {}
102111

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 {}
112+
unsafe impl<T: PointeeSized> Freeze for PhantomData<T> {}
113+
unsafe impl<T: PointeeSized> Freeze for *const T {}
114+
unsafe impl<T: PointeeSized> Freeze for *mut T {}
115+
unsafe impl<T: PointeeSized> Freeze for &T {}
116+
unsafe impl<T: PointeeSized> Freeze for &mut T {}
108117

109118
#[lang = "structural_peq"]
110119
pub trait StructuralPartialEq {}
@@ -443,7 +452,7 @@ pub enum Option<T> {
443452
pub use Option::*;
444453

445454
#[lang = "phantom_data"]
446-
pub struct PhantomData<T: ?Sized>;
455+
pub struct PhantomData<T: PointeeSized>;
447456

448457
#[lang = "fn_once"]
449458
#[rustc_paren_sugar]
@@ -546,18 +555,18 @@ pub trait Deref {
546555
#[repr(transparent)]
547556
#[rustc_layout_scalar_valid_range_start(1)]
548557
#[rustc_nonnull_optimization_guaranteed]
549-
pub struct NonNull<T: ?Sized>(pub *const T);
558+
pub struct NonNull<T: PointeeSized>(pub *const T);
550559

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> {}
560+
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
561+
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
553562

554-
pub struct Unique<T: ?Sized> {
563+
pub struct Unique<T: PointeeSized> {
555564
pub pointer: NonNull<T>,
556565
pub _marker: PhantomData<T>,
557566
}
558567

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> {}
568+
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
569+
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
561570

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

compiler/rustc_codegen_gcc/example/mini_core.rs

+39-31
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![feature(
22
no_core, lang_items, intrinsics, unboxed_closures, extern_types,
33
decl_macro, rustc_attrs, transparent_unions, auto_traits, freeze_impls,
4-
thread_local
4+
thread_local, const_trait_impl
55
)]
66
#![no_core]
77
#![allow(dead_code, internal_features, ambiguous_wide_pointer_comparisons)]
@@ -11,8 +11,16 @@ unsafe extern "C" fn _Unwind_Resume() {
1111
intrinsics::unreachable();
1212
}
1313

14+
#[lang = "pointeesized"]
15+
pub trait PointeeSized {}
16+
17+
#[lang = "metasized"]
18+
#[const_trait]
19+
pub trait MetaSized: PointeeSized {}
20+
1421
#[lang = "sized"]
15-
pub trait Sized {}
22+
#[const_trait]
23+
pub trait Sized: MetaSized {}
1624

1725
#[lang = "destruct"]
1826
pub trait Destruct {}
@@ -21,35 +29,35 @@ pub trait Destruct {}
2129
pub trait Tuple {}
2230

2331
#[lang = "unsize"]
24-
pub trait Unsize<T: ?Sized> {}
32+
pub trait Unsize<T: PointeeSized>: PointeeSized {}
2533

2634
#[lang = "coerce_unsized"]
2735
pub trait CoerceUnsized<T> {}
2836

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 {}
37+
impl<'a, 'b: 'a, T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<&'a U> for &'b T {}
38+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<&'a mut U> for &'a mut T {}
39+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<*const U> for *const T {}
40+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<*mut U> for *mut T {}
3341

3442
#[lang = "dispatch_from_dyn"]
3543
pub trait DispatchFromDyn<T> {}
3644

3745
// &T -> &U
38-
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
46+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<&'a U> for &'a T {}
3947
// &mut T -> &mut U
40-
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
48+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<&'a mut U> for &'a mut T {}
4149
// *const T -> *const U
42-
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
50+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<*const U> for *const T {}
4351
// *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, ()> {}
52+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<*mut U> for *mut T {}
53+
impl<T: MetaSized + Unsize<U>, U: MetaSized> DispatchFromDyn<Box<U, ()>> for Box<T, ()> {}
4654

4755
#[lang = "legacy_receiver"]
4856
pub trait LegacyReceiver {}
4957

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> {}
58+
impl<T: PointeeSized> LegacyReceiver for &T {}
59+
impl<T: PointeeSized> LegacyReceiver for &mut T {}
60+
impl<T: MetaSized> LegacyReceiver for Box<T> {}
5361

5462
#[lang = "copy"]
5563
pub trait Copy {}
@@ -70,9 +78,9 @@ impl Copy for isize {}
7078
impl Copy for f32 {}
7179
impl Copy for f64 {}
7280
impl Copy for char {}
73-
impl<'a, T: ?Sized> Copy for &'a T {}
74-
impl<T: ?Sized> Copy for *const T {}
75-
impl<T: ?Sized> Copy for *mut T {}
81+
impl<'a, T: PointeeSized> Copy for &'a T {}
82+
impl<T: PointeeSized> Copy for *const T {}
83+
impl<T: PointeeSized> Copy for *mut T {}
7684

7785
#[lang = "sync"]
7886
pub unsafe trait Sync {}
@@ -88,17 +96,17 @@ unsafe impl Sync for i16 {}
8896
unsafe impl Sync for i32 {}
8997
unsafe impl Sync for isize {}
9098
unsafe impl Sync for char {}
91-
unsafe impl<'a, T: ?Sized> Sync for &'a T {}
99+
unsafe impl<'a, T: PointeeSized> Sync for &'a T {}
92100
unsafe impl Sync for [u8; 16] {}
93101

94102
#[lang = "freeze"]
95103
unsafe auto trait Freeze {}
96104

97-
unsafe impl<T: ?Sized> Freeze for PhantomData<T> {}
98-
unsafe impl<T: ?Sized> Freeze for *const T {}
99-
unsafe impl<T: ?Sized> Freeze for *mut T {}
100-
unsafe impl<T: ?Sized> Freeze for &T {}
101-
unsafe impl<T: ?Sized> Freeze for &mut T {}
105+
unsafe impl<T: PointeeSized> Freeze for PhantomData<T> {}
106+
unsafe impl<T: PointeeSized> Freeze for *const T {}
107+
unsafe impl<T: PointeeSized> Freeze for *mut T {}
108+
unsafe impl<T: PointeeSized> Freeze for &T {}
109+
unsafe impl<T: PointeeSized> Freeze for &mut T {}
102110

103111
#[lang = "structural_peq"]
104112
pub trait StructuralPartialEq {}
@@ -403,7 +411,7 @@ pub enum Option<T> {
403411
pub use Option::*;
404412

405413
#[lang = "phantom_data"]
406-
pub struct PhantomData<T: ?Sized>;
414+
pub struct PhantomData<T: PointeeSized>;
407415

408416
#[lang = "fn_once"]
409417
#[rustc_paren_sugar]
@@ -520,18 +528,18 @@ impl Allocator for Global {}
520528
#[repr(transparent)]
521529
#[rustc_layout_scalar_valid_range_start(1)]
522530
#[rustc_nonnull_optimization_guaranteed]
523-
pub struct NonNull<T: ?Sized>(pub *const T);
531+
pub struct NonNull<T: PointeeSized>(pub *const T);
524532

525-
impl<T: ?Sized, U: ?Sized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
526-
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
533+
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
534+
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
527535

528-
pub struct Unique<T: ?Sized> {
536+
pub struct Unique<T: PointeeSized> {
529537
pub pointer: NonNull<T>,
530538
pub _marker: PhantomData<T>,
531539
}
532540

533-
impl<T: ?Sized, U: ?Sized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
534-
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
541+
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
542+
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
535543

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

0 commit comments

Comments
 (0)