@@ -4,7 +4,6 @@ pub use self::BorrowKind::*;
44pub use self :: IntVarValue :: * ;
55pub use self :: Variance :: * ;
66
7- use crate :: arena:: Arena ;
87use crate :: hir:: exports:: ExportMap ;
98use crate :: ich:: StableHashingContext ;
109use crate :: infer:: canonical:: Canonical ;
@@ -43,13 +42,11 @@ use rustc_span::Span;
4342use rustc_target:: abi:: { Align , VariantIdx } ;
4443
4544use std:: cell:: RefCell ;
46- use std:: cmp:: { self , Ordering } ;
45+ use std:: cmp:: Ordering ;
4746use std:: fmt;
4847use std:: hash:: { Hash , Hasher } ;
49- use std:: ops:: Deref ;
5048use std:: ops:: Range ;
51- use std:: slice;
52- use std:: { mem, ptr} ;
49+ use std:: ptr;
5350
5451pub use self :: sty:: BoundRegion :: * ;
5552pub use self :: sty:: InferTy :: * ;
@@ -81,6 +78,8 @@ pub use self::context::{
8178
8279pub use self :: instance:: { Instance , InstanceDef } ;
8380
81+ pub use self :: list:: List ;
82+
8483pub use self :: trait_def:: TraitDef ;
8584
8685pub use self :: query:: queries;
@@ -112,6 +111,7 @@ pub mod walk;
112111mod context;
113112mod diagnostics;
114113mod instance;
114+ mod list;
115115mod structural_impls;
116116mod sty;
117117
@@ -663,148 +663,9 @@ pub type Ty<'tcx> = &'tcx TyS<'tcx>;
663663
664664impl < ' tcx > rustc_serialize:: UseSpecializedEncodable for Ty < ' tcx > { }
665665impl < ' 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-
796666impl < ' tcx > rustc_serialize:: UseSpecializedDecodable for & ' tcx List < Ty < ' tcx > > { }
797667
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 > > ;
808669
809670#[ derive( Clone , Copy , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable , HashStable ) ]
810671pub struct UpvarPath {
0 commit comments