@@ -4,7 +4,6 @@ pub use self::BorrowKind::*;
4
4
pub use self :: IntVarValue :: * ;
5
5
pub use self :: Variance :: * ;
6
6
7
- use crate :: arena:: Arena ;
8
7
use crate :: hir:: exports:: ExportMap ;
9
8
use crate :: ich:: StableHashingContext ;
10
9
use crate :: infer:: canonical:: Canonical ;
@@ -43,13 +42,11 @@ use rustc_span::Span;
43
42
use rustc_target:: abi:: { Align , VariantIdx } ;
44
43
45
44
use std:: cell:: RefCell ;
46
- use std:: cmp:: { self , Ordering } ;
45
+ use std:: cmp:: Ordering ;
47
46
use std:: fmt;
48
47
use std:: hash:: { Hash , Hasher } ;
49
- use std:: ops:: Deref ;
50
48
use std:: ops:: Range ;
51
- use std:: slice;
52
- use std:: { mem, ptr} ;
49
+ use std:: ptr;
53
50
54
51
pub use self :: sty:: BoundRegion :: * ;
55
52
pub use self :: sty:: InferTy :: * ;
@@ -81,6 +78,8 @@ pub use self::context::{
81
78
82
79
pub use self :: instance:: { Instance , InstanceDef } ;
83
80
81
+ pub use self :: list:: List ;
82
+
84
83
pub use self :: trait_def:: TraitDef ;
85
84
86
85
pub use self :: query:: queries;
@@ -112,6 +111,7 @@ pub mod walk;
112
111
mod context;
113
112
mod diagnostics;
114
113
mod instance;
114
+ mod list;
115
115
mod structural_impls;
116
116
mod sty;
117
117
@@ -663,148 +663,9 @@ pub type Ty<'tcx> = &'tcx TyS<'tcx>;
663
663
664
664
impl < ' tcx > rustc_serialize:: UseSpecializedEncodable for Ty < ' tcx > { }
665
665
impl < ' tcx > rustc_serialize:: UseSpecializedDecodable for Ty < ' tcx > { }
666
-
667
- pub type CanonicalTy < ' tcx > = Canonical < ' tcx , Ty < ' tcx > > ;
668
-
669
- extern "C" {
670
- /// A dummy type used to force `List` to be unsized while not requiring references to it be wide
671
- /// pointers.
672
- type OpaqueListContents ;
673
- }
674
-
675
- /// A wrapper for slices with the additional invariant
676
- /// that the slice is interned and no other slice with
677
- /// the same contents can exist in the same context.
678
- /// This means we can use pointer for both
679
- /// equality comparisons and hashing.
680
- /// Note: `Slice` was already taken by the `Ty`.
681
- #[ repr( C ) ]
682
- pub struct List < T > {
683
- len : usize ,
684
- data : [ T ; 0 ] ,
685
- opaque : OpaqueListContents ,
686
- }
687
-
688
- unsafe impl < T : Sync > Sync for List < T > { }
689
-
690
- impl < T : Copy > List < T > {
691
- #[ inline]
692
- fn from_arena < ' tcx > ( arena : & ' tcx Arena < ' tcx > , slice : & [ T ] ) -> & ' tcx List < T > {
693
- assert ! ( !mem:: needs_drop:: <T >( ) ) ;
694
- assert ! ( mem:: size_of:: <T >( ) != 0 ) ;
695
- assert ! ( !slice. is_empty( ) ) ;
696
-
697
- // Align up the size of the len (usize) field
698
- let align = mem:: align_of :: < T > ( ) ;
699
- let align_mask = align - 1 ;
700
- let offset = mem:: size_of :: < usize > ( ) ;
701
- let offset = ( offset + align_mask) & !align_mask;
702
-
703
- let size = offset + slice. len ( ) * mem:: size_of :: < T > ( ) ;
704
-
705
- let mem = arena
706
- . dropless
707
- . alloc_raw ( size, cmp:: max ( mem:: align_of :: < T > ( ) , mem:: align_of :: < usize > ( ) ) ) ;
708
- unsafe {
709
- let result = & mut * ( mem. as_mut_ptr ( ) as * mut List < T > ) ;
710
- // Write the length
711
- result. len = slice. len ( ) ;
712
-
713
- // Write the elements
714
- let arena_slice = slice:: from_raw_parts_mut ( result. data . as_mut_ptr ( ) , result. len ) ;
715
- arena_slice. copy_from_slice ( slice) ;
716
-
717
- result
718
- }
719
- }
720
- }
721
-
722
- impl < T : fmt:: Debug > fmt:: Debug for List < T > {
723
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
724
- ( * * self ) . fmt ( f)
725
- }
726
- }
727
-
728
- impl < T : Encodable > Encodable for List < T > {
729
- #[ inline]
730
- fn encode < S : Encoder > ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
731
- ( * * self ) . encode ( s)
732
- }
733
- }
734
-
735
- impl < T > Ord for List < T >
736
- where
737
- T : Ord ,
738
- {
739
- fn cmp ( & self , other : & List < T > ) -> Ordering {
740
- if self == other { Ordering :: Equal } else { <[ T ] as Ord >:: cmp ( & * * self , & * * other) }
741
- }
742
- }
743
-
744
- impl < T > PartialOrd for List < T >
745
- where
746
- T : PartialOrd ,
747
- {
748
- fn partial_cmp ( & self , other : & List < T > ) -> Option < Ordering > {
749
- if self == other {
750
- Some ( Ordering :: Equal )
751
- } else {
752
- <[ T ] as PartialOrd >:: partial_cmp ( & * * self , & * * other)
753
- }
754
- }
755
- }
756
-
757
- impl < T : PartialEq > PartialEq for List < T > {
758
- #[ inline]
759
- fn eq ( & self , other : & List < T > ) -> bool {
760
- ptr:: eq ( self , other)
761
- }
762
- }
763
- impl < T : Eq > Eq for List < T > { }
764
-
765
- impl < T > Hash for List < T > {
766
- #[ inline]
767
- fn hash < H : Hasher > ( & self , s : & mut H ) {
768
- ( self as * const List < T > ) . hash ( s)
769
- }
770
- }
771
-
772
- impl < T > Deref for List < T > {
773
- type Target = [ T ] ;
774
- #[ inline( always) ]
775
- fn deref ( & self ) -> & [ T ] {
776
- self . as_ref ( )
777
- }
778
- }
779
-
780
- impl < T > AsRef < [ T ] > for List < T > {
781
- #[ inline( always) ]
782
- fn as_ref ( & self ) -> & [ T ] {
783
- unsafe { slice:: from_raw_parts ( self . data . as_ptr ( ) , self . len ) }
784
- }
785
- }
786
-
787
- impl < ' a , T > IntoIterator for & ' a List < T > {
788
- type Item = & ' a T ;
789
- type IntoIter = <& ' a [ T ] as IntoIterator >:: IntoIter ;
790
- #[ inline( always) ]
791
- fn into_iter ( self ) -> Self :: IntoIter {
792
- self [ ..] . iter ( )
793
- }
794
- }
795
-
796
666
impl < ' tcx > rustc_serialize:: UseSpecializedDecodable for & ' tcx List < Ty < ' tcx > > { }
797
667
798
- impl < T > List < T > {
799
- #[ inline( always) ]
800
- pub fn empty < ' a > ( ) -> & ' a List < T > {
801
- #[ repr( align( 64 ) , C ) ]
802
- struct EmptySlice ( [ u8 ; 64 ] ) ;
803
- static EMPTY_SLICE : EmptySlice = EmptySlice ( [ 0 ; 64 ] ) ;
804
- assert ! ( mem:: align_of:: <T >( ) <= 64 ) ;
805
- unsafe { & * ( & EMPTY_SLICE as * const _ as * const List < T > ) }
806
- }
807
- }
668
+ pub type CanonicalTy < ' tcx > = Canonical < ' tcx , Ty < ' tcx > > ;
808
669
809
670
#[ derive( Clone , Copy , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable , HashStable ) ]
810
671
pub struct UpvarPath {
0 commit comments