1
1
#![ feature(
2
2
no_core, lang_items, intrinsics, unboxed_closures, type_ascription, extern_types,
3
- untagged_unions , decl_macro, rustc_attrs, transparent_unions, auto_traits,
3
+ decl_macro, rustc_attrs, transparent_unions, auto_traits,
4
4
thread_local
5
5
) ]
6
6
#![ no_core]
@@ -39,14 +39,14 @@ impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut
39
39
impl < T : ?Sized +Unsize < U > , U : ?Sized > DispatchFromDyn < * const U > for * const T { }
40
40
// *mut T -> *mut U
41
41
impl < T : ?Sized +Unsize < U > , U : ?Sized > DispatchFromDyn < * mut U > for * mut T { }
42
- impl < T : ?Sized + Unsize < U > , U : ?Sized > DispatchFromDyn < Box < U > > for Box < T > { }
42
+ impl < T : ?Sized + Unsize < U > , U : ?Sized > DispatchFromDyn < Box < U , ( ) > > for Box < T , ( ) > { }
43
43
44
44
#[ lang = "receiver" ]
45
45
pub trait Receiver { }
46
46
47
47
impl < T : ?Sized > Receiver for & T { }
48
48
impl < T : ?Sized > Receiver for & mut T { }
49
- impl < T : ?Sized > Receiver for Box < T > { }
49
+ impl < T : ?Sized , A : Allocator > Receiver for Box < T , A > { }
50
50
51
51
#[ lang = "copy" ]
52
52
pub unsafe trait Copy { }
@@ -411,7 +411,15 @@ pub trait FnMut<Args>: FnOnce<Args> {
411
411
412
412
#[ lang = "panic" ]
413
413
#[ track_caller]
414
- pub fn panic ( _msg : & str ) -> ! {
414
+ pub fn panic ( _msg : & ' static str ) -> ! {
415
+ unsafe {
416
+ libc:: puts ( "Panicking\n \0 " as * const str as * const u8 ) ;
417
+ intrinsics:: abort ( ) ;
418
+ }
419
+ }
420
+
421
+ #[ lang = "panic_no_unwind" ]
422
+ fn panic_no_unwind ( ) -> ! {
415
423
unsafe {
416
424
libc:: puts ( "Panicking\n \0 " as * const str as * const u8 ) ;
417
425
intrinsics:: abort ( ) ;
@@ -450,25 +458,40 @@ pub trait Deref {
450
458
pub trait Allocator {
451
459
}
452
460
461
+ impl Allocator for ( ) { }
462
+
453
463
pub struct Global ;
454
464
455
465
impl Allocator for Global { }
456
466
467
+ #[ repr( transparent) ]
468
+ #[ rustc_layout_scalar_valid_range_start( 1 ) ]
469
+ #[ rustc_nonnull_optimization_guaranteed]
470
+ pub struct NonNull < T : ?Sized > ( pub * const T ) ;
471
+
472
+ impl < T : ?Sized , U : ?Sized > CoerceUnsized < NonNull < U > > for NonNull < T > where T : Unsize < U > { }
473
+ impl < T : ?Sized , U : ?Sized > DispatchFromDyn < NonNull < U > > for NonNull < T > where T : Unsize < U > { }
474
+
475
+ pub struct Unique < T : ?Sized > {
476
+ pub pointer : NonNull < T > ,
477
+ pub _marker : PhantomData < T > ,
478
+ }
479
+
480
+ impl < T : ?Sized , U : ?Sized > CoerceUnsized < Unique < U > > for Unique < T > where T : Unsize < U > { }
481
+ impl < T : ?Sized , U : ?Sized > DispatchFromDyn < Unique < U > > for Unique < T > where T : Unsize < U > { }
482
+
457
483
#[ lang = "owned_box" ]
458
- pub struct Box <
459
- T : ?Sized ,
460
- A : Allocator = Global ,
461
- > ( * mut T , A ) ;
484
+ pub struct Box < T : ?Sized , A : Allocator = Global > ( Unique < T > , A ) ;
462
485
463
- impl < T : ?Sized + Unsize < U > , U : ?Sized > CoerceUnsized < Box < U > > for Box < T > { }
486
+ impl < T : ?Sized + Unsize < U > , U : ?Sized , A : Allocator > CoerceUnsized < Box < U , A > > for Box < T , A > { }
464
487
465
488
impl < T : ?Sized , A : Allocator > Drop for Box < T , A > {
466
489
fn drop ( & mut self ) {
467
490
// drop is currently performed by compiler.
468
491
}
469
492
}
470
493
471
- impl < T > Deref for Box < T > {
494
+ impl < T : ? Sized , A : Allocator > Deref for Box < T , A > {
472
495
type Target = T ;
473
496
474
497
fn deref ( & self ) -> & Self :: Target {
@@ -482,8 +505,8 @@ unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
482
505
}
483
506
484
507
#[ lang = "box_free" ]
485
- unsafe fn box_free < T : ?Sized , A : Allocator > ( ptr : * mut T , alloc : A ) {
486
- libc:: free ( ptr as * mut u8 ) ;
508
+ unsafe fn box_free < T : ?Sized > ( ptr : Unique < T > , _alloc : ( ) ) {
509
+ libc:: free ( ptr. pointer . 0 as * mut u8 ) ;
487
510
}
488
511
489
512
#[ lang = "drop" ]
@@ -505,16 +528,18 @@ pub union MaybeUninit<T> {
505
528
}
506
529
507
530
pub mod intrinsics {
531
+ use crate :: Sized ;
532
+
508
533
extern "rust-intrinsic" {
509
534
pub fn abort ( ) -> !;
510
535
pub fn size_of < T > ( ) -> usize ;
511
- pub fn size_of_val < T : ?:: Sized > ( val : * const T ) -> usize ;
536
+ pub fn size_of_val < T : ?Sized > ( val : * const T ) -> usize ;
512
537
pub fn min_align_of < T > ( ) -> usize ;
513
- pub fn min_align_of_val < T : ?:: Sized > ( val : * const T ) -> usize ;
538
+ pub fn min_align_of_val < T : ?Sized > ( val : * const T ) -> usize ;
514
539
pub fn copy < T > ( src : * const T , dst : * mut T , count : usize ) ;
515
540
pub fn transmute < T , U > ( e : T ) -> U ;
516
541
pub fn ctlz_nonzero < T > ( x : T ) -> T ;
517
- pub fn needs_drop < T : ?:: Sized > ( ) -> bool ;
542
+ pub fn needs_drop < T : ?Sized > ( ) -> bool ;
518
543
pub fn bitreverse < T > ( x : T ) -> T ;
519
544
pub fn bswap < T > ( x : T ) -> T ;
520
545
pub fn write_bytes < T > ( dst : * mut T , val : u8 , count : usize ) ;
0 commit comments