Skip to content

Commit ee977e7

Browse files
committed
rustc_trans: don't lose the cross-crate DefId, MIR trans needs it.
1 parent 32e462e commit ee977e7

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/librustc_trans/base.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1918,9 +1918,9 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
19181918
}
19191919

19201920
pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance<'tcx>) {
1921-
let instance = inline::maybe_inline_instance(ccx, instance);
1921+
let local_instance = inline::maybe_inline_instance(ccx, instance);
19221922

1923-
let fn_node_id = ccx.tcx().map.as_local_node_id(instance.def).unwrap();
1923+
let fn_node_id = ccx.tcx().map.as_local_node_id(local_instance.def).unwrap();
19241924

19251925
let _s = StatRecorder::new(ccx, ccx.tcx().node_path_str(fn_node_id));
19261926
debug!("trans_instance(instance={:?})", instance);
@@ -1936,7 +1936,7 @@ pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance
19361936
let sig = ccx.tcx().normalize_associated_type(&sig);
19371937
let abi = fn_ty.fn_abi();
19381938

1939-
let lldecl = match ccx.instances().borrow().get(&instance) {
1939+
let lldecl = match ccx.instances().borrow().get(&local_instance) {
19401940
Some(&val) => val,
19411941
None => bug!("Instance `{:?}` not already declared", instance)
19421942
};

src/librustc_trans/debuginfo/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use rustc::hir;
3232

3333
use abi::Abi;
3434
use common::{NodeIdAndSpan, CrateContext, FunctionContext, Block, BlockAndBuilder};
35+
use inline;
3536
use monomorphize::{self, Instance};
3637
use rustc::ty::{self, Ty};
3738
use session::config::{self, FullDebugInfo, LimitedDebugInfo, NoDebugInfo};
@@ -238,6 +239,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
238239
// Do this here already, in case we do an early exit from this function.
239240
source_loc::set_debug_location(cx, None, UnknownLocation);
240241

242+
let instance = inline::maybe_inline_instance(cx, instance);
241243
let (containing_scope, span) = get_containing_scope_and_span(cx, instance);
242244

243245
// This can be the case for functions inlined from another crate

src/test/run-pass/mir_cross_crate.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -Z orbit
12+
// Tests that -Z orbit affects functions from other crates.
13+
14+
#![feature(unsafe_no_drop_flag)]
15+
16+
#[unsafe_no_drop_flag]
17+
struct Foo;
18+
19+
impl Drop for Foo {
20+
fn drop(&mut self) {
21+
panic!("MIR trans is not enabled for mem::forget");
22+
}
23+
}
24+
25+
fn main() {
26+
let x = Foo;
27+
std::mem::forget(x);
28+
}

0 commit comments

Comments
 (0)