]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_codegen_ssa/meth.rs
Auto merge of #67900 - nikic:prepare-llvm-10, r=nagisa
[rust.git] / src / librustc_codegen_ssa / meth.rs
index 692027390ec1b04eb157f1f04bd27dda6630eb88..c36ef9b480cf0610b390ebc27c6d5c8cc400782c 100644 (file)
@@ -1,8 +1,7 @@
-use rustc_target::abi::call::FnAbi;
-
 use crate::traits::*;
 
-use rustc::ty::{self, Ty, Instance};
+use rustc::ty::{self, Instance, Ty};
+use rustc_target::abi::call::FnAbi;
 
 #[derive(Copy, Clone, Debug)]
 pub struct VirtualIndex(u64);
@@ -20,20 +19,17 @@ pub fn get_fn<Bx: BuilderMethods<'a, 'tcx>>(
         self,
         bx: &mut Bx,
         llvtable: Bx::Value,
-        fn_abi: &FnAbi<'tcx, Ty<'tcx>>
+        fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
     ) -> Bx::Value {
         // Load the data pointer from the object.
         debug!("get_fn({:?}, {:?})", llvtable, self);
 
-        let llvtable = bx.pointercast(
-            llvtable,
-            bx.type_ptr_to(bx.fn_ptr_backend_type(fn_abi))
-        );
+        let llvtable = bx.pointercast(llvtable, bx.type_ptr_to(bx.fn_ptr_backend_type(fn_abi)));
         let ptr_align = bx.tcx().data_layout.pointer_align.abi;
         let gep = bx.inbounds_gep(llvtable, &[bx.const_usize(self.0)]);
         let ptr = bx.load(gep, ptr_align);
         bx.nonnull_metadata(ptr);
-        // Vtable loads are invariant
+        // Vtable loads are invariant.
         bx.set_invariant_load(ptr);
         ptr
     }
@@ -41,7 +37,7 @@ pub fn get_fn<Bx: BuilderMethods<'a, 'tcx>>(
     pub fn get_usize<Bx: BuilderMethods<'a, 'tcx>>(
         self,
         bx: &mut Bx,
-        llvtable: Bx::Value
+        llvtable: Bx::Value,
     ) -> Bx::Value {
         // Load the data pointer from the object.
         debug!("get_int({:?}, {:?})", llvtable, self);
@@ -50,7 +46,7 @@ pub fn get_usize<Bx: BuilderMethods<'a, 'tcx>>(
         let usize_align = bx.tcx().data_layout.pointer_align.abi;
         let gep = bx.inbounds_gep(llvtable, &[bx.const_usize(self.0)]);
         let ptr = bx.load(gep, usize_align);
-        // Vtable loads are invariant
+        // Vtable loads are invariant.
         bx.set_invariant_load(ptr);
         ptr
     }
@@ -63,7 +59,7 @@ pub fn get_usize<Bx: BuilderMethods<'a, 'tcx>>(
 ///
 /// The `trait_ref` encodes the erased self type. Hence if we are
 /// making an object `Foo<dyn Trait>` from a value of type `Foo<T>`, then
-/// `trait_ref` would map `T:Trait`.
+/// `trait_ref` would map `T: Trait`.
 pub fn get_vtable<'tcx, Cx: CodegenMethods<'tcx>>(
     cx: &Cx,
     ty: Ty<'tcx>,
@@ -78,7 +74,7 @@ pub fn get_vtable<'tcx, Cx: CodegenMethods<'tcx>>(
         return val;
     }
 
-    // Not in the cache. Build it.
+    // Not in the cache; build it.
     let nullptr = cx.const_null(cx.type_i8p());
 
     let methods_root;
@@ -97,7 +93,8 @@ pub fn get_vtable<'tcx, Cx: CodegenMethods<'tcx>>(
                     ty::ParamEnv::reveal_all(),
                     def_id,
                     substs,
-                ).unwrap()
+                )
+                .unwrap(),
             )
         })
     });
@@ -105,13 +102,17 @@ pub fn get_vtable<'tcx, Cx: CodegenMethods<'tcx>>(
     let layout = cx.layout_of(ty);
     // /////////////////////////////////////////////////////////////////////////////////////////////
     // If you touch this code, be sure to also make the corresponding changes to
-    // `get_vtable` in rust_mir/interpret/traits.rs
+    // `get_vtable` in `rust_mir/interpret/traits.rs`.
     // /////////////////////////////////////////////////////////////////////////////////////////////
     let components: Vec<_> = [
         cx.get_fn_addr(Instance::resolve_drop_in_place(cx.tcx(), ty)),
         cx.const_usize(layout.size.bytes()),
-        cx.const_usize(layout.align.abi.bytes())
-    ].iter().cloned().chain(methods).collect();
+        cx.const_usize(layout.align.abi.bytes()),
+    ]
+    .iter()
+    .cloned()
+    .chain(methods)
+    .collect();
 
     let vtable_const = cx.const_struct(&components, false);
     let align = cx.data_layout().pointer_align.abi;