@@ -40,6 +40,16 @@ use hash::Hasher;
40
40
/// [ub]: ../../reference/behavior-considered-undefined.html
41
41
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
42
42
#[ cfg_attr( stage0, lang = "send" ) ]
43
+ #[ cfg( not( stage0) ) ]
44
+ #[ rustc_on_unimplemented = "`{Self}` cannot be sent between threads safely" ]
45
+ pub unsafe trait Send : ?DynSized {
46
+ // empty.
47
+ }
48
+
49
+ /// docs
50
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
51
+ #[ cfg_attr( stage0, lang = "send" ) ]
52
+ #[ cfg( stage0) ]
43
53
#[ rustc_on_unimplemented = "`{Self}` cannot be sent between threads safely" ]
44
54
pub unsafe trait Send {
45
55
// empty.
@@ -51,9 +61,9 @@ pub unsafe trait Send {
51
61
unsafe impl Send for .. { }
52
62
53
63
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
54
- impl < T : ?Sized > !Send for * const T { }
64
+ impl < T : ?DynSized > !Send for * const T { }
55
65
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
56
- impl < T : ?Sized > !Send for * mut T { }
66
+ impl < T : ?DynSized > !Send for * mut T { }
57
67
58
68
/// Types with a constant size known at compile time.
59
69
///
@@ -96,6 +106,29 @@ pub trait Sized {
96
106
// Empty.
97
107
}
98
108
109
+ /// Types with a size known at run time.
110
+ ///
111
+ /// This trait is implemented both by `Sized` types, and by dynamically sized
112
+ /// types such as slices and [trait objects]. [Extern types], whose size is not
113
+ /// known, even at runtime, do not implement this trait.
114
+ ///
115
+ /// All traits and type parameters have an implicit bound of `DynSized`. The
116
+ /// special syntax `?DynSized` can be used to remove this bound if it's not
117
+ /// appropriate.
118
+ ///
119
+ /// [trait object]: ../../book/first-edition/trait-objects.html
120
+ #[ cfg( not( stage0) ) ]
121
+ #[ unstable( feature = "dynsized" , issue = "0" ) ]
122
+ #[ lang = "dynsized" ]
123
+ #[ rustc_on_unimplemented = "`{Self}` does not have a size known at run-time" ]
124
+ #[ fundamental]
125
+ pub trait DynSized : ?DynSized {
126
+ // Empty.
127
+ }
128
+
129
+ #[ cfg( stage0) ]
130
+ use self :: Sized as DynSized ; // This is just so we don't have to stage too much stuff
131
+
99
132
/// Types that can be "unsized" to a dynamically-sized type.
100
133
///
101
134
/// For example, the sized array type `[i8; 2]` implements `Unsize<[i8]>` and
@@ -345,6 +378,16 @@ pub trait Copy : Clone {
345
378
/// [transmute]: ../../std/mem/fn.transmute.html
346
379
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
347
380
#[ lang = "sync" ]
381
+ #[ cfg( not( stage0) ) ]
382
+ #[ rustc_on_unimplemented = "`{Self}` cannot be shared between threads safely" ]
383
+ pub unsafe trait Sync : ?DynSized {
384
+ // Empty
385
+ }
386
+
387
+ /// docs
388
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
389
+ #[ lang = "sync" ]
390
+ #[ cfg( stage0) ]
348
391
#[ rustc_on_unimplemented = "`{Self}` cannot be shared between threads safely" ]
349
392
pub unsafe trait Sync {
350
393
// Empty
@@ -356,56 +399,56 @@ pub unsafe trait Sync {
356
399
unsafe impl Sync for .. { }
357
400
358
401
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
359
- impl < T : ?Sized > !Sync for * const T { }
402
+ impl < T : ?DynSized > !Sync for * const T { }
360
403
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
361
- impl < T : ?Sized > !Sync for * mut T { }
404
+ impl < T : ?DynSized > !Sync for * mut T { }
362
405
363
406
macro_rules! impls{
364
407
( $t: ident) => (
365
408
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
366
- impl <T : ?Sized > Hash for $t<T > {
409
+ impl <T : ?DynSized > Hash for $t<T > {
367
410
#[ inline]
368
411
fn hash<H : Hasher >( & self , _: & mut H ) {
369
412
}
370
413
}
371
414
372
415
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
373
- impl <T : ?Sized > cmp:: PartialEq for $t<T > {
416
+ impl <T : ?DynSized > cmp:: PartialEq for $t<T > {
374
417
fn eq( & self , _other: & $t<T >) -> bool {
375
418
true
376
419
}
377
420
}
378
421
379
422
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
380
- impl <T : ?Sized > cmp:: Eq for $t<T > {
423
+ impl <T : ?DynSized > cmp:: Eq for $t<T > {
381
424
}
382
425
383
426
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
384
- impl <T : ?Sized > cmp:: PartialOrd for $t<T > {
427
+ impl <T : ?DynSized > cmp:: PartialOrd for $t<T > {
385
428
fn partial_cmp( & self , _other: & $t<T >) -> Option <cmp:: Ordering > {
386
429
Option :: Some ( cmp:: Ordering :: Equal )
387
430
}
388
431
}
389
432
390
433
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
391
- impl <T : ?Sized > cmp:: Ord for $t<T > {
434
+ impl <T : ?DynSized > cmp:: Ord for $t<T > {
392
435
fn cmp( & self , _other: & $t<T >) -> cmp:: Ordering {
393
436
cmp:: Ordering :: Equal
394
437
}
395
438
}
396
439
397
440
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
398
- impl <T : ?Sized > Copy for $t<T > { }
441
+ impl <T : ?DynSized > Copy for $t<T > { }
399
442
400
443
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
401
- impl <T : ?Sized > Clone for $t<T > {
444
+ impl <T : ?DynSized > Clone for $t<T > {
402
445
fn clone( & self ) -> $t<T > {
403
446
$t
404
447
}
405
448
}
406
449
407
450
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
408
- impl <T : ?Sized > Default for $t<T > {
451
+ impl <T : ?DynSized > Default for $t<T > {
409
452
fn default ( ) -> $t<T > {
410
453
$t
411
454
}
@@ -548,31 +591,35 @@ macro_rules! impls{
548
591
/// [drop check]: ../../nomicon/dropck.html
549
592
#[ lang = "phantom_data" ]
550
593
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
551
- pub struct PhantomData < T : ?Sized > ;
594
+ pub struct PhantomData < T : ?DynSized > ;
552
595
553
596
impls ! { PhantomData }
554
597
555
- mod impls {
556
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
557
- unsafe impl < ' a , T : Sync + ?Sized > Send for & ' a T { }
558
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
559
- unsafe impl < ' a , T : Send + ?Sized > Send for & ' a mut T { }
560
- }
598
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
599
+ unsafe impl < ' a , T : Sync + ?DynSized > Send for & ' a T { }
600
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
601
+ unsafe impl < ' a , T : Send + ?DynSized > Send for & ' a mut T { }
561
602
562
603
/// Compiler-internal trait used to determine whether a type contains
563
604
/// any `UnsafeCell` internally, but not through an indirection.
564
605
/// This affects, for example, whether a `static` of that type is
565
606
/// placed in read-only static memory or writable static memory.
566
607
#[ lang = "freeze" ]
608
+ #[ cfg( not( stage0) ) ]
609
+ unsafe trait Freeze : ?DynSized { }
610
+
611
+ /// docs
612
+ #[ lang = "freeze" ]
613
+ #[ cfg( stage0) ]
567
614
unsafe trait Freeze { }
568
615
569
616
#[ allow( unknown_lints) ]
570
617
#[ allow( auto_impl) ]
571
618
unsafe impl Freeze for .. { }
572
619
573
- impl < T : ?Sized > !Freeze for UnsafeCell < T > { }
574
- unsafe impl < T : ?Sized > Freeze for PhantomData < T > { }
575
- unsafe impl < T : ?Sized > Freeze for * const T { }
576
- unsafe impl < T : ?Sized > Freeze for * mut T { }
577
- unsafe impl < ' a , T : ?Sized > Freeze for & ' a T { }
578
- unsafe impl < ' a , T : ?Sized > Freeze for & ' a mut T { }
620
+ impl < T : ?DynSized > !Freeze for UnsafeCell < T > { }
621
+ unsafe impl < T : ?DynSized > Freeze for PhantomData < T > { }
622
+ unsafe impl < T : ?DynSized > Freeze for * const T { }
623
+ unsafe impl < T : ?DynSized > Freeze for * mut T { }
624
+ unsafe impl < ' a , T : ?DynSized > Freeze for & ' a T { }
625
+ unsafe impl < ' a , T : ?DynSized > Freeze for & ' a mut T { }
0 commit comments