]> git.lizzy.rs Git - rust.git/commitdiff
translate / export weak lang items
authorJorge Aparicio <jorge@japaric.io>
Thu, 21 Jun 2018 18:01:16 +0000 (13:01 -0500)
committerJorge Aparicio <jorge@japaric.io>
Thu, 21 Jun 2018 18:02:17 +0000 (13:02 -0500)
see #51671 for details

fixes #51671
fixes #51342

src/librustc/middle/weak_lang_items.rs
src/librustc_mir/monomorphize/collector.rs
src/test/run-make-fulldeps/issue-51671/Makefile [new file with mode: 0644]
src/test/run-make-fulldeps/issue-51671/app.rs [new file with mode: 0644]

index 3c2ea047218a7bfb16d119383a0b23af10c24a94..1d147eef054f300b64a707bfc3f599f063b92609 100644 (file)
@@ -17,6 +17,7 @@
 use syntax::ast;
 use syntax::symbol::Symbol;
 use syntax_pos::Span;
+use hir::def_id::DefId;
 use hir::intravisit::{Visitor, NestedVisitorMap};
 use hir::intravisit;
 use hir;
@@ -145,6 +146,15 @@ fn visit_foreign_item(&mut self, i: &hir::ForeignItem) {
     }
 }
 
+impl<'a, 'tcx, 'gcx> TyCtxt<'a, 'tcx, 'gcx> {
+    pub fn is_weak_lang_item(&self, item_def_id: DefId) -> bool {
+        let lang_items = self.lang_items();
+        let did = Some(item_def_id);
+
+        $(lang_items.$name() == did)||+
+    }
+}
+
 ) }
 
 weak_lang_items! {
index 96aeb969d89f96eb20f367b49609748498373db2..c5f2730b9deb4906e5c8526d0b0012ce3d390b48 100644 (file)
@@ -1031,6 +1031,7 @@ fn is_root(&self, def_id: DefId) -> bool {
             MonoItemCollectionMode::Lazy => {
                 self.entry_fn == Some(def_id) ||
                 self.tcx.is_reachable_non_generic(def_id) ||
+                self.tcx.is_weak_lang_item(def_id) ||
                 self.tcx.codegen_fn_attrs(def_id).flags.contains(
                     CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL)
             }
diff --git a/src/test/run-make-fulldeps/issue-51671/Makefile b/src/test/run-make-fulldeps/issue-51671/Makefile
new file mode 100644 (file)
index 0000000..bdb5ca8
--- /dev/null
@@ -0,0 +1,13 @@
+-include ../tools.mk
+
+ifdef IS_WINDOWS
+# Do nothing on MSVC.
+all:
+       exit 0
+else
+all:
+       $(RUSTC) --emit=obj app.rs
+       nm $(TMPDIR)/app.o | $(CGREP) rust_begin_unwind
+       nm $(TMPDIR)/app.o | $(CGREP) rust_eh_personality
+       nm $(TMPDIR)/app.o | $(CGREP) rust_oom
+endif
diff --git a/src/test/run-make-fulldeps/issue-51671/app.rs b/src/test/run-make-fulldeps/issue-51671/app.rs
new file mode 100644 (file)
index 0000000..c524b4d
--- /dev/null
@@ -0,0 +1,18 @@
+#![crate_type = "bin"]
+#![feature(lang_items)]
+#![feature(panic_implementation)]
+#![no_main]
+#![no_std]
+
+use core::panic::PanicInfo;
+
+#[panic_implementation]
+fn panic(_: &PanicInfo) -> ! {
+    loop {}
+}
+
+#[lang = "eh_personality"]
+fn eh() {}
+
+#[lang = "oom"]
+fn oom() {}