Skip to content

Commit

Permalink
fix cross-crate destructor inlining
Browse files Browse the repository at this point in the history
Closes #7793
  • Loading branch information
thestinger committed Nov 3, 2013
1 parent b2f62ac commit e582702
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,16 +521,23 @@ pub fn get_res_dtor(ccx: @mut CrateContext,
substs: &[ty::t])
-> ValueRef {
let _icx = push_ctxt("trans_res_dtor");
let did = if did.crate != ast::LOCAL_CRATE {
inline::maybe_instantiate_inline(ccx, did)
} else {
did
};
if !substs.is_empty() {
let did = if did.crate != ast::LOCAL_CRATE {
inline::maybe_instantiate_inline(ccx, did)
} else {
did
};
assert_eq!(did.crate, ast::LOCAL_CRATE);
let tsubsts = ty::substs {regions: ty::ErasedRegions,
self_ty: None,
tps: /*bad*/ substs.to_owned() };

// FIXME: #4252: Generic destructors with type bounds are broken.
//
// Since the vtables aren't passed to `monomorphic_fn` here, generic destructors with type
// bounds are broken. Sadly, the `typeck` pass isn't outputting the necessary metadata
// because it does so based on method calls present in the AST. Destructor calls are not yet
// known about at that stage of compilation, since `trans` handles cleanups.
let (val, _) = monomorphize::monomorphic_fn(ccx,
did,
&tsubsts,
Expand Down
18 changes: 18 additions & 0 deletions src/test/auxiliary/inline_dtor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2013 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.

#[link(name="inline_dtor", vers="0.1")];

pub struct Foo;

impl Drop for Foo {
#[inline]
fn drop(&mut self) {}
}
18 changes: 18 additions & 0 deletions src/test/run-pass/use_inline_dtor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2013 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.

// aux-build:inline_dtor.rs
// xfail-fast

extern mod inline_dtor;

fn main() {
let _x = inline_dtor::Foo;
}

5 comments on commit e582702

@bors
Copy link
Contributor

@bors bors commented on e582702 Nov 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on e582702 Nov 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging thestinger/rust/inline_dtor = e582702 into auto

@bors
Copy link
Contributor

@bors bors commented on e582702 Nov 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thestinger/rust/inline_dtor = e582702 merged ok, testing candidate = 4910b7a

@bors
Copy link
Contributor

@bors bors commented on e582702 Nov 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on e582702 Nov 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 4910b7a

Please sign in to comment.