about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-06-28 15:34:17 +0000
committerbors <bors@rust-lang.org>2018-06-28 15:34:17 +0000
commite3bf634e060bc2f8665878288bcea02008ca346e (patch)
tree717f212d7ce8c325fac856efdef3b0692d4ef2ec
parent5d95db34a472dc09a90737c83ab533b840dcd224 (diff)
parentcce70073feedd50f6f78545d0572f3072e8a4f49 (diff)
downloadrust-e3bf634e060bc2f8665878288bcea02008ca346e.tar.gz
rust-e3bf634e060bc2f8665878288bcea02008ca346e.zip
Auto merge of #51687 - japaric:gh51671, r=alexcrichton
translate / export weak lang items

see #51671 for details

fixes #51671
fixes #51342

r? @michaelwoerister or @alexcrichton
-rw-r--r--src/librustc/middle/weak_lang_items.rs10
-rw-r--r--src/librustc_mir/monomorphize/collector.rs1
-rw-r--r--src/test/run-make-fulldeps/issue-51671/Makefile13
-rw-r--r--src/test/run-make-fulldeps/issue-51671/app.rs28
4 files changed, 52 insertions, 0 deletions
diff --git a/src/librustc/middle/weak_lang_items.rs b/src/librustc/middle/weak_lang_items.rs
index 3c2ea047218..1d147eef054 100644
--- a/src/librustc/middle/weak_lang_items.rs
+++ b/src/librustc/middle/weak_lang_items.rs
@@ -17,6 +17,7 @@ use rustc_target::spec::PanicStrategy;
 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 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
     }
 }
 
+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! {
diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs
index c079b9d3dc4..a65ee065ca6 100644
--- a/src/librustc_mir/monomorphize/collector.rs
+++ b/src/librustc_mir/monomorphize/collector.rs
@@ -1031,6 +1031,7 @@ impl<'b, 'a, 'v> RootCollector<'b, 'a, 'v> {
             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
index 00000000000..bdb5ca81720
--- /dev/null
+++ b/src/test/run-make-fulldeps/issue-51671/Makefile
@@ -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
index 00000000000..720ce1512f2
--- /dev/null
+++ b/src/test/run-make-fulldeps/issue-51671/app.rs
@@ -0,0 +1,28 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![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() {}