Skip to content

Commit e582702

Browse files
committed
fix cross-crate destructor inlining
Closes #7793
1 parent b2f62ac commit e582702

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

src/librustc/middle/trans/base.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -521,16 +521,23 @@ pub fn get_res_dtor(ccx: @mut CrateContext,
521521
substs: &[ty::t])
522522
-> ValueRef {
523523
let _icx = push_ctxt("trans_res_dtor");
524+
let did = if did.crate != ast::LOCAL_CRATE {
525+
inline::maybe_instantiate_inline(ccx, did)
526+
} else {
527+
did
528+
};
524529
if !substs.is_empty() {
525-
let did = if did.crate != ast::LOCAL_CRATE {
526-
inline::maybe_instantiate_inline(ccx, did)
527-
} else {
528-
did
529-
};
530530
assert_eq!(did.crate, ast::LOCAL_CRATE);
531531
let tsubsts = ty::substs {regions: ty::ErasedRegions,
532532
self_ty: None,
533533
tps: /*bad*/ substs.to_owned() };
534+
535+
// FIXME: #4252: Generic destructors with type bounds are broken.
536+
//
537+
// Since the vtables aren't passed to `monomorphic_fn` here, generic destructors with type
538+
// bounds are broken. Sadly, the `typeck` pass isn't outputting the necessary metadata
539+
// because it does so based on method calls present in the AST. Destructor calls are not yet
540+
// known about at that stage of compilation, since `trans` handles cleanups.
534541
let (val, _) = monomorphize::monomorphic_fn(ccx,
535542
did,
536543
&tsubsts,

src/test/auxiliary/inline_dtor.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
#[link(name="inline_dtor", vers="0.1")];
12+
13+
pub struct Foo;
14+
15+
impl Drop for Foo {
16+
#[inline]
17+
fn drop(&mut self) {}
18+
}

src/test/run-pass/use_inline_dtor.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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:inline_dtor.rs
12+
// xfail-fast
13+
14+
extern mod inline_dtor;
15+
16+
fn main() {
17+
let _x = inline_dtor::Foo;
18+
}

0 commit comments

Comments
 (0)