]> git.lizzy.rs Git - rust.git/commitdiff
Implement some traits for FunctionCx
authorbjorn3 <bjorn3@users.noreply.github.com>
Sun, 24 Jun 2018 12:25:29 +0000 (14:25 +0200)
committerbjorn3 <bjorn3@users.noreply.github.com>
Sun, 24 Jun 2018 12:25:29 +0000 (14:25 +0200)
src/common.rs

index d753255bfa9b74b9503d20576955ff9eca87aa7c..8a8e29bbda5f07ac472fac95fd14713301e620bc 100644 (file)
@@ -1,4 +1,7 @@
+extern crate rustc_target;
+
 use syntax::ast::{IntTy, UintTy};
+use self::rustc_target::spec::{HasTargetSpec, Target};
 
 use cretonne_module::{Module, Linkage, FuncId};
 
@@ -277,6 +280,24 @@ fn layout_of(self, ty: Ty<'tcx>) -> TyLayout<'tcx> {
     }
 }
 
+impl<'a, 'tcx> layout::HasTyCtxt<'tcx> for &'a FunctionCx<'a, 'tcx> {
+    fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> {
+        self.tcx
+    }
+}
+
+impl<'a, 'tcx> layout::HasDataLayout for &'a FunctionCx<'a, 'tcx> {
+    fn data_layout(&self) -> &layout::TargetDataLayout {
+        &self.tcx.data_layout
+    }
+}
+
+impl<'a, 'tcx> HasTargetSpec for &'a FunctionCx<'a, 'tcx> {
+    fn target_spec(&self) -> &Target {
+        &self.tcx.sess.target.target
+    }
+}
+
 impl<'f, 'tcx> FunctionCx<'f, 'tcx> {
     pub fn monomorphize<T>(&self, value: &T) -> T
         where T: TypeFoldable<'tcx>