]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_codegen_ssa/mono_item.rs
Rollup merge of #61550 - jacobsun:patch-1, r=alexcrichton
[rust.git] / src / librustc_codegen_ssa / mono_item.rs
index 48159d7979923803c69477df5ebae4877cf74fe0..11e9a48133d9a2aff18b6b54fcdd60e0d26aedd3 100644 (file)
@@ -1,35 +1,32 @@
 use rustc::hir;
-use rustc::hir::def::Def;
 use rustc::mir::mono::{Linkage, Visibility};
 use rustc::ty::layout::HasTyCtxt;
-use std::fmt;
 use crate::base;
 use crate::traits::*;
 
-pub use rustc::mir::mono::MonoItem;
+use rustc::mir::mono::MonoItem;
 
-pub use rustc_mir::monomorphize::item::MonoItemExt as BaseMonoItemExt;
+pub trait MonoItemExt<'a, 'tcx: 'a> {
+    fn define<Bx: BuilderMethods<'a, 'tcx>>(&self, cx: &'a Bx::CodegenCx);
+    fn predefine<Bx: BuilderMethods<'a, 'tcx>>(
+        &self,
+        cx: &'a Bx::CodegenCx,
+        linkage: Linkage,
+        visibility: Visibility
+    );
+    fn to_raw_string(&self) -> String;
+}
 
-pub trait MonoItemExt<'a, 'tcx: 'a>: fmt::Debug + BaseMonoItemExt<'a, 'tcx> {
+impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
     fn define<Bx: BuilderMethods<'a, 'tcx>>(&self, cx: &'a Bx::CodegenCx) {
         debug!("BEGIN IMPLEMENTING '{} ({})' in cgu {}",
                self.to_string(cx.tcx(), true),
                self.to_raw_string(),
                cx.codegen_unit().name());
 
-        match *self.as_mono_item() {
+        match *self {
             MonoItem::Static(def_id) => {
-                let tcx = cx.tcx();
-                let is_mutable = match tcx.describe_def(def_id) {
-                    Some(Def::Static(_, is_mutable)) => is_mutable,
-                    Some(other) => {
-                        bug!("Expected Def::Static, found {:?}", other)
-                    }
-                    None => {
-                        bug!("Expected Def::Static for {:?}, found nothing", def_id)
-                    }
-                };
-                cx.codegen_static(def_id, is_mutable);
+                cx.codegen_static(def_id, cx.tcx().is_mutable_static(def_id));
             }
             MonoItem::GlobalAsm(hir_id) => {
                 let item = cx.tcx().hir().expect_item_by_hir_id(hir_id);
@@ -65,7 +62,7 @@ fn predefine<Bx: BuilderMethods<'a, 'tcx>>(
 
         debug!("symbol {}", &symbol_name);
 
-        match *self.as_mono_item() {
+        match *self {
             MonoItem::Static(def_id) => {
                 cx.predefine_static(def_id, linkage, visibility, &symbol_name);
             }
@@ -82,7 +79,7 @@ fn predefine<Bx: BuilderMethods<'a, 'tcx>>(
     }
 
     fn to_raw_string(&self) -> String {
-        match *self.as_mono_item() {
+        match *self {
             MonoItem::Fn(instance) => {
                 format!("Fn({:?}, {})",
                         instance.def,
@@ -97,5 +94,3 @@ fn to_raw_string(&self) -> String {
         }
     }
 }
-
-impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {}