Skip to content

Commit a1ffb06

Browse files
committed
Use the correct logging crate while monomorphing
This makes sure that the top-level crate name is correct when emitting log statements for a monomorphized function in another crate. This happens by tracing the monomorphized ID back to the external source and then using that crate index to get the name of the crate. Closes #3046
1 parent 320af9b commit a1ffb06

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

src/librustc/middle/trans/expr.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ use back::link;
119119
use lib::llvm::{ValueRef, llvm, SetLinkage, False};
120120
use lib;
121121
use metadata::csearch;
122+
use metadata::cstore;
122123
use middle::trans::_match;
123124
use middle::trans::adt;
124125
use middle::trans::asm;
@@ -1797,9 +1798,14 @@ pub fn trans_log_level(bcx: @mut Block) -> DatumBlock {
17971798
let ccx = bcx.ccx();
17981799

17991800
let (modpath, modname) = {
1800-
let path = &mut bcx.fcx.path;
1801-
let mut modpath = ~[path_mod(ccx.sess.ident_of(ccx.link_meta.name))];
1802-
for e in path.iter() {
1801+
let srccrate = match ccx.external_srcs.find(&bcx.fcx.id) {
1802+
Some(&src) => {
1803+
cstore::get_crate_data(ccx.sess.cstore, src.crate).name
1804+
}
1805+
None => ccx.link_meta.name,
1806+
};
1807+
let mut modpath = ~[path_mod(ccx.sess.ident_of(srccrate))];
1808+
for e in bcx.fcx.path.iter() {
18031809
match *e {
18041810
path_mod(_) => { modpath.push(*e) }
18051811
_ => {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2013 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+
pub fn foo<T>() {
12+
fn death() -> int { fail2!() }
13+
debug2!("{:?}", (||{ death() })());
14+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2013 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+
// aux-build:logging_right_crate.rs
12+
// xfail-fast
13+
// exec-env:RUST_LOG=logging-right-crate=debug
14+
15+
// This is a test for issue #3046 to make sure that when we monomorphize a
16+
// function from one crate to another the right top-level logging name is
17+
// preserved.
18+
//
19+
// It used to be the case that if logging were turned on for this crate, all
20+
// monomorphized functions from other crates had logging turned on (their
21+
// logging module names were all incorrect). This test ensures that this no
22+
// longer happens by enabling logging for *this* crate and then invoking a
23+
// function in an external crate which will fail when logging is enabled.
24+
25+
extern mod logging_right_crate;
26+
27+
fn main() {
28+
// this function fails if logging is turned on
29+
logging_right_crate::foo::<int>();
30+
}

0 commit comments

Comments
 (0)