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