Skip to content

Commit eab1648

Browse files
authored
Rollup merge of rust-lang#44553 - qmx:refactor-remove-overzealous-box-szero-optimization, r=arielb1
remove overzealous Box<ZeroSizeType> optimization
2 parents efdcd5e + 916ccc5 commit eab1648

File tree

2 files changed

+2
-40
lines changed

2 files changed

+2
-40
lines changed

src/librustc_trans/glue.rs

+1-38
Original file line numberDiff line numberDiff line change
@@ -16,51 +16,14 @@ use std;
1616

1717
use llvm;
1818
use llvm::{ValueRef};
19-
use rustc::traits;
20-
use rustc::ty::{self, Ty, TypeFoldable};
19+
use rustc::ty::{self, Ty};
2120
use rustc::ty::layout::LayoutTyper;
2221
use common::*;
2322
use meth;
2423
use monomorphize;
2524
use value::Value;
2625
use builder::Builder;
2726

28-
pub fn needs_drop_glue<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>, t: Ty<'tcx>) -> bool {
29-
assert!(t.is_normalized_for_trans());
30-
31-
let t = scx.tcx().erase_regions(&t);
32-
33-
// FIXME (#22815): note that type_needs_drop conservatively
34-
// approximates in some cases and may say a type expression
35-
// requires drop glue when it actually does not.
36-
//
37-
// (In this case it is not clear whether any harm is done, i.e.
38-
// erroneously returning `true` in some cases where we could have
39-
// returned `false` does not appear unsound. The impact on
40-
// code quality is unknown at this time.)
41-
42-
if !scx.type_needs_drop(t) {
43-
return false;
44-
}
45-
match t.sty {
46-
ty::TyAdt(def, _) if def.is_box() => {
47-
let typ = t.boxed_ty();
48-
if !scx.type_needs_drop(typ) && scx.type_is_sized(typ) {
49-
let layout = t.layout(scx.tcx(), ty::ParamEnv::empty(traits::Reveal::All)).unwrap();
50-
if layout.size(scx).bytes() == 0 {
51-
// `Box<ZeroSizeType>` does not allocate.
52-
false
53-
} else {
54-
true
55-
}
56-
} else {
57-
true
58-
}
59-
}
60-
_ => true
61-
}
62-
}
63-
6427
pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, info: ValueRef)
6528
-> (ValueRef, ValueRef) {
6629
debug!("calculate size of DST: {}; with lost info: {:?}",

src/librustc_trans/monomorphize.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use abi::Abi;
1212
use common::*;
13-
use glue;
1413

1514
use rustc::hir::def_id::DefId;
1615
use rustc::middle::lang_items::DropInPlaceFnLangItem;
@@ -189,7 +188,7 @@ pub fn resolve<'a, 'tcx>(
189188
_ => {
190189
if Some(def_id) == scx.tcx().lang_items().drop_in_place_fn() {
191190
let ty = substs.type_at(0);
192-
if glue::needs_drop_glue(scx, ty) {
191+
if scx.type_needs_drop(ty) {
193192
debug!(" => nontrivial drop glue");
194193
ty::InstanceDef::DropGlue(def_id, Some(ty))
195194
} else {

0 commit comments

Comments
 (0)