]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/arena.rs
Auto merge of #67596 - Mark-Simulacrum:tidy-silence-rustfmt, r=Centril
[rust.git] / src / librustc / arena.rs
index 364a35f1b6faa1ed0328b2d7c1790ea26b0a6342..3d5bd313f88384adb01c34ac126060f2dc33a549 100644 (file)
@@ -1,10 +1,10 @@
-use arena::{TypedArena, DroplessArena};
+use arena::{DroplessArena, TypedArena};
+use smallvec::SmallVec;
+use std::cell::RefCell;
+use std::marker::PhantomData;
 use std::mem;
 use std::ptr;
 use std::slice;
-use std::cell::RefCell;
-use std::marker::PhantomData;
-use smallvec::SmallVec;
 
 /// This declares a list of types which can be allocated by `Arena`.
 ///
@@ -23,17 +23,17 @@ macro_rules! arena_types {
             [] generics: rustc::ty::Generics,
             [] trait_def: rustc::ty::TraitDef,
             [] adt_def: rustc::ty::AdtDef,
-            [] steal_mir: rustc::ty::steal::Steal<rustc::mir::BodyCache<$tcx>>,
-            [] mir: rustc::mir::BodyCache<$tcx>,
+            [] steal_mir: rustc::ty::steal::Steal<rustc::mir::BodyAndCache<$tcx>>,
+            [] mir: rustc::mir::BodyAndCache<$tcx>,
             [] steal_promoted: rustc::ty::steal::Steal<
                 rustc_index::vec::IndexVec<
                     rustc::mir::Promoted,
-                    rustc::mir::BodyCache<$tcx>
+                    rustc::mir::BodyAndCache<$tcx>
                 >
             >,
             [] promoted: rustc_index::vec::IndexVec<
                 rustc::mir::Promoted,
-                rustc::mir::BodyCache<$tcx>
+                rustc::mir::BodyAndCache<$tcx>
             >,
             [] tables: rustc::ty::TypeckTables<$tcx>,
             [] const_allocs: rustc::mir::interpret::Allocation,
@@ -93,7 +93,6 @@ macro_rules! arena_types {
                         rustc::hir::def_id::CrateNum
                     >
                 >,
-            [few] hir_forest: rustc::hir::map::Forest,
             [few] diagnostic_items: rustc_data_structures::fx::FxHashMap<
                 syntax::symbol::Symbol,
                 rustc::hir::def_id::DefId,
@@ -123,6 +122,21 @@ macro_rules! arena_types {
             [few] crate_variances: rustc::ty::CrateVariancesMap<'tcx>,
             [few] inferred_outlives_crate: rustc::ty::CratePredicatesMap<'tcx>,
             [] upvars: rustc_data_structures::fx::FxIndexMap<rustc::hir::HirId, rustc::hir::Upvar>,
+
+            // HIR types
+            [few] hir_forest: rustc::hir::map::Forest<$tcx>,
+            [] attribute: syntax::ast::Attribute,
+            [few] global_asm: rustc::hir::GlobalAsm,
+            [] fn_decl: rustc::hir::FnDecl,
+            [] foreign_item: rustc::hir::ForeignItem<$tcx>,
+            [] impl_item_ref: rustc::hir::ImplItemRef,
+            [few] macro_def: rustc::hir::MacroDef<$tcx>,
+            [] param: rustc::hir::Param,
+            [] path: rustc::hir::Path,
+            [] struct_field: rustc::hir::StructField<$tcx>,
+            [] trait_item_ref: rustc::hir::TraitItemRef,
+            [] ty: rustc::hir::Ty,
+            [] variant: rustc::hir::Variant<$tcx>,
         ], $tcx);
     )
 }
@@ -212,17 +226,14 @@ pub fn alloc<T: ArenaAllocatable>(&self, value: T) -> &mut T {
     #[inline]
     pub fn alloc_slice<T: Copy>(&self, value: &[T]) -> &mut [T] {
         if value.len() == 0 {
-            return &mut []
+            return &mut [];
         }
         self.dropless.alloc_slice(value)
     }
 
-    pub fn alloc_from_iter<
-        T: ArenaAllocatable,
-        I: IntoIterator<Item = T>
-    >(
+    pub fn alloc_from_iter<T: ArenaAllocatable, I: IntoIterator<Item = T>>(
         &'a self,
-        iter: I
+        iter: I,
     ) -> &'a mut [T] {
         if !mem::needs_drop::<T>() {
             return self.dropless.alloc_from_iter(iter);
@@ -246,9 +257,7 @@ unsafe fn drop_for_type<T>(to_drop: *mut u8) {
 
 impl Drop for DropType {
     fn drop(&mut self) {
-        unsafe {
-            (self.drop_fn)(self.obj)
-        }
+        unsafe { (self.drop_fn)(self.obj) }
     }
 }
 
@@ -269,19 +278,16 @@ struct DropArena {
 impl DropArena {
     #[inline]
     unsafe fn alloc<T>(&self, object: T) -> &mut T {
-        let mem = self.arena.alloc_raw(
-            mem::size_of::<T>(),
-            mem::align_of::<T>()
-        ) as *mut _ as *mut T;
+        let mem =
+            self.arena.alloc_raw(mem::size_of::<T>(), mem::align_of::<T>()) as *mut _ as *mut T;
         // Write into uninitialized memory.
         ptr::write(mem, object);
         let result = &mut *mem;
         // Record the destructor after doing the allocation as that may panic
         // and would cause `object`'s destuctor to run twice if it was recorded before
-        self.destructors.borrow_mut().push(DropType {
-            drop_fn: drop_for_type::<T>,
-            obj: result as *mut T as *mut u8,
-        });
+        self.destructors
+            .borrow_mut()
+            .push(DropType { drop_fn: drop_for_type::<T>, obj: result as *mut T as *mut u8 });
         result
     }
 
@@ -293,10 +299,10 @@ unsafe fn alloc_from_iter<T, I: IntoIterator<Item = T>>(&self, iter: I) -> &mut
         }
         let len = vec.len();
 
-        let start_ptr = self.arena.alloc_raw(
-            len.checked_mul(mem::size_of::<T>()).unwrap(),
-            mem::align_of::<T>()
-        ) as *mut _ as *mut T;
+        let start_ptr = self
+            .arena
+            .alloc_raw(len.checked_mul(mem::size_of::<T>()).unwrap(), mem::align_of::<T>())
+            as *mut _ as *mut T;
 
         let mut destructors = self.destructors.borrow_mut();
         // Reserve space for the destructors so we can't panic while adding them