Skip to content

Commit 21f86ba

Browse files
Simplify handling of dropping structs.
1 parent 7dadd14 commit 21f86ba

File tree

2 files changed

+11
-66
lines changed

2 files changed

+11
-66
lines changed

src/librustc_trans/common.rs

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use llvm;
1616
use llvm::{ValueRef, ContextRef, TypeKind};
1717
use llvm::{True, False, Bool, OperandBundleDef};
18-
use rustc::hir::def::Def;
1918
use rustc::hir::def_id::DefId;
2019
use rustc::hir::map::DefPathData;
2120
use rustc::util::common::MemoizationMap;
@@ -38,7 +37,7 @@ use std::borrow::Cow;
3837
use std::iter;
3938

4039
use syntax::ast;
41-
use syntax::symbol::{Symbol, InternedString};
40+
use syntax::symbol::InternedString;
4241
use syntax_pos::Span;
4342

4443
use rustc_i128::u128;
@@ -169,55 +168,6 @@ pub fn type_is_zero_size<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -
169168
*
170169
*/
171170

172-
use Disr;
173-
174-
/// The concrete version of ty::FieldDef. The name is the field index if
175-
/// the field is numeric.
176-
pub struct Field<'tcx>(pub ast::Name, pub Ty<'tcx>);
177-
178-
/// The concrete version of ty::VariantDef
179-
pub struct VariantInfo<'tcx> {
180-
pub discr: Disr,
181-
pub fields: Vec<Field<'tcx>>
182-
}
183-
184-
impl<'a, 'tcx> VariantInfo<'tcx> {
185-
pub fn from_ty(tcx: TyCtxt<'a, 'tcx, 'tcx>,
186-
ty: Ty<'tcx>,
187-
opt_def: Option<Def>)
188-
-> Self
189-
{
190-
match ty.sty {
191-
ty::TyAdt(adt, substs) => {
192-
let variant = match opt_def {
193-
None => adt.struct_variant(),
194-
Some(def) => adt.variant_of_def(def)
195-
};
196-
197-
VariantInfo {
198-
discr: Disr::from(variant.disr_val),
199-
fields: variant.fields.iter().map(|f| {
200-
Field(f.name, monomorphize::field_ty(tcx, substs, f))
201-
}).collect()
202-
}
203-
}
204-
205-
ty::TyTuple(ref v) => {
206-
VariantInfo {
207-
discr: Disr(0),
208-
fields: v.iter().enumerate().map(|(i, &t)| {
209-
Field(Symbol::intern(&i.to_string()), t)
210-
}).collect()
211-
}
212-
}
213-
214-
_ => {
215-
bug!("cannot get field types from the type {:?}", ty);
216-
}
217-
}
218-
}
219-
}
220-
221171
/// A structure representing an active landing pad for the duration of a basic
222172
/// block.
223173
///

src/librustc_trans/glue.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// Code relating to drop glue.
1414

1515
use std;
16+
use std::ptr;
1617
use std::iter;
1718

1819
use llvm;
@@ -444,21 +445,15 @@ fn drop_structural_ty<'a, 'tcx>(
444445
}
445446
ty::TyAdt(adt, substs) => match adt.adt_kind() {
446447
AdtKind::Struct => {
447-
let VariantInfo { fields, discr } = VariantInfo::from_ty(cx.tcx(), t, None);
448-
for (i, &Field(_, field_ty)) in fields.iter().enumerate() {
449-
let mut ptr = ptr.clone();
450-
ptr.ty = LvalueTy::Downcast {
451-
adt_def: adt,
452-
substs: substs,
453-
variant_index: Disr::from(discr).0 as usize,
454-
};
455-
let llfld_a = ptr.trans_field_ptr(&cx, i);
456-
let ptr = if cx.ccx.shared().type_is_sized(field_ty) {
457-
LvalueRef::new_sized_ty(llfld_a, field_ty)
458-
} else {
459-
LvalueRef::new_unsized_ty(llfld_a, ptr.llextra, field_ty)
460-
};
461-
drop_ty(&cx, ptr);
448+
for (i, field) in adt.variants[0].fields.iter().enumerate() {
449+
let field_ty = monomorphize::field_ty(cx.tcx(), substs, field);
450+
let mut field_ptr = ptr.clone();
451+
field_ptr.llval = ptr.trans_field_ptr(&cx, i);
452+
field_ptr.ty = LvalueTy::from_ty(field_ty);
453+
if cx.ccx.shared().type_is_sized(field_ty) {
454+
field_ptr.llextra = ptr::null_mut();
455+
}
456+
drop_ty(&cx, field_ptr);
462457
}
463458
}
464459
AdtKind::Union => {

0 commit comments

Comments
 (0)