about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEduard Burtescu <edy.burt@gmail.com>2016-08-03 01:25:34 +0300
committerEduard Burtescu <edy.burt@gmail.com>2016-08-03 01:25:34 +0300
commitee977e715f7714b728d2d1603b2f6e1b3f1a1e5f (patch)
treea72a26ca6761caea585360cf1c262527a7f6e40f
parent32e462ef99e2f61b75e2b0ef37048d50ad8ccf6c (diff)
downloadrust-ee977e715f7714b728d2d1603b2f6e1b3f1a1e5f.tar.gz
rust-ee977e715f7714b728d2d1603b2f6e1b3f1a1e5f.zip
rustc_trans: don't lose the cross-crate DefId, MIR trans needs it.
-rw-r--r--src/librustc_trans/base.rs6
-rw-r--r--src/librustc_trans/debuginfo/mod.rs2
-rw-r--r--src/test/run-pass/mir_cross_crate.rs28
3 files changed, 33 insertions, 3 deletions
diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs
index 5a19ddff746..6d9ae4deb71 100644
--- a/src/librustc_trans/base.rs
+++ b/src/librustc_trans/base.rs
@@ -1918,9 +1918,9 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
 }
 
 pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance<'tcx>) {
-    let instance = inline::maybe_inline_instance(ccx, instance);
+    let local_instance = inline::maybe_inline_instance(ccx, instance);
 
-    let fn_node_id = ccx.tcx().map.as_local_node_id(instance.def).unwrap();
+    let fn_node_id = ccx.tcx().map.as_local_node_id(local_instance.def).unwrap();
 
     let _s = StatRecorder::new(ccx, ccx.tcx().node_path_str(fn_node_id));
     debug!("trans_instance(instance={:?})", instance);
@@ -1936,7 +1936,7 @@ pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance
     let sig = ccx.tcx().normalize_associated_type(&sig);
     let abi = fn_ty.fn_abi();
 
-    let lldecl = match ccx.instances().borrow().get(&instance) {
+    let lldecl = match ccx.instances().borrow().get(&local_instance) {
         Some(&val) => val,
         None => bug!("Instance `{:?}` not already declared", instance)
     };
diff --git a/src/librustc_trans/debuginfo/mod.rs b/src/librustc_trans/debuginfo/mod.rs
index 0cb52c8768b..918935988a9 100644
--- a/src/librustc_trans/debuginfo/mod.rs
+++ b/src/librustc_trans/debuginfo/mod.rs
@@ -32,6 +32,7 @@ use rustc::hir;
 
 use abi::Abi;
 use common::{NodeIdAndSpan, CrateContext, FunctionContext, Block, BlockAndBuilder};
+use inline;
 use monomorphize::{self, Instance};
 use rustc::ty::{self, Ty};
 use session::config::{self, FullDebugInfo, LimitedDebugInfo, NoDebugInfo};
@@ -238,6 +239,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
     // Do this here already, in case we do an early exit from this function.
     source_loc::set_debug_location(cx, None, UnknownLocation);
 
+    let instance = inline::maybe_inline_instance(cx, instance);
     let (containing_scope, span) = get_containing_scope_and_span(cx, instance);
 
     // This can be the case for functions inlined from another crate
diff --git a/src/test/run-pass/mir_cross_crate.rs b/src/test/run-pass/mir_cross_crate.rs
new file mode 100644
index 00000000000..cc239d9f68b
--- /dev/null
+++ b/src/test/run-pass/mir_cross_crate.rs
@@ -0,0 +1,28 @@
+// Copyright 2016 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.
+
+// compile-flags: -Z orbit
+// Tests that -Z orbit affects functions from other crates.
+
+#![feature(unsafe_no_drop_flag)]
+
+#[unsafe_no_drop_flag]
+struct Foo;
+
+impl Drop for Foo {
+    fn drop(&mut self) {
+        panic!("MIR trans is not enabled for mem::forget");
+    }
+}
+
+fn main() {
+    let x = Foo;
+    std::mem::forget(x);
+}