Skip to content

Commit 9dc9f34

Browse files
authored
Auto merge of #36468 - michaelwoerister:collect-vtable-drop-glue, r=eddyb
trans: Let the collector find drop-glue for all vtables, not just VTableImpl. This fixes #36260. So far, the collector has only recorded drop-glue for insertion into a vtable if the vtable was for an impl. But there's actually no reason why it shouldn't do just the same for closure vtables, afaict. r? @eddyb cc @rust-lang/compiler
2 parents d4037fc + 1b3a588 commit 9dc9f34

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

src/librustc_trans/collector.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
497497
self.output);
498498
}
499499
}
500-
mir::Rvalue::Box(_) => {
500+
mir::Rvalue::Box(..) => {
501501
let exchange_malloc_fn_def_id =
502502
self.scx
503503
.tcx()
@@ -1072,15 +1072,16 @@ fn create_trans_items_for_vtable_methods<'a, 'tcx>(scx: &SharedCrateContext<'a,
10721072
});
10731073

10741074
output.extend(items);
1075-
1076-
// Also add the destructor
1077-
let dg_type = glue::get_drop_glue_type(scx.tcx(),
1078-
trait_ref.self_ty());
1079-
output.push(TransItem::DropGlue(DropGlueKind::Ty(dg_type)));
10801075
}
10811076
_ => { /* */ }
10821077
}
10831078
}
1079+
1080+
// Also add the destructor
1081+
let dg_type = glue::get_drop_glue_type(scx.tcx(), impl_ty);
1082+
if glue::type_needs_drop(scx.tcx(), dg_type) {
1083+
output.push(TransItem::DropGlue(DropGlueKind::Ty(dg_type)));
1084+
}
10841085
}
10851086
}
10861087

src/test/codegen-units/item-collection/instantiation-through-vtable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,3 @@ fn main() {
4040
//~ TRANS_ITEM fn instantiation_through_vtable::{{impl}}[0]::bar[0]<u64>
4141
let _ = &s1 as &Trait;
4242
}
43-
44-
//~ TRANS_ITEM drop-glue i8

src/test/codegen-units/item-collection/unsizing.rs

-2
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,3 @@ fn main()
7878
//~ TRANS_ITEM fn unsizing::{{impl}}[3]::foo[0]
7979
let _wrapper_sized = wrapper_sized as Wrapper<Trait>;
8080
}
81-
82-
//~ TRANS_ITEM drop-glue i8

src/test/codegen-units/partitioning/vtable-through-const.rs

-2
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,3 @@ fn main() {
8989
//~ TRANS_ITEM fn vtable_through_const::mod1[0]::id[0]<char> @@ vtable_through_const[Internal]
9090
mod1::ID_CHAR('x');
9191
}
92-
93-
//~ TRANS_ITEM drop-glue i8

src/test/run-pass/issue36260.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2012-2015 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+
// Make sure this compiles without getting a linker error because of missing
12+
// drop-glue because the collector missed adding drop-glue for the closure:
13+
14+
fn create_fn() -> Box<Fn()> {
15+
let text = String::new();
16+
17+
Box::new(move || { let _ = &text; })
18+
}
19+
20+
fn main() {
21+
let _ = create_fn();
22+
}

0 commit comments

Comments
 (0)