use llvm;
use llvm::{ValueRef, ContextRef, TypeKind};
use llvm::{True, False, Bool, OperandBundleDef};
-use rustc::hir::def::Def;
use rustc::hir::def_id::DefId;
use rustc::hir::map::DefPathData;
use rustc::util::common::MemoizationMap;
use std::iter;
use syntax::ast;
-use syntax::symbol::{Symbol, InternedString};
+use syntax::symbol::InternedString;
use syntax_pos::Span;
use rustc_i128::u128;
*
*/
-use Disr;
-
-/// The concrete version of ty::FieldDef. The name is the field index if
-/// the field is numeric.
-pub struct Field<'tcx>(pub ast::Name, pub Ty<'tcx>);
-
-/// The concrete version of ty::VariantDef
-pub struct VariantInfo<'tcx> {
- pub discr: Disr,
- pub fields: Vec<Field<'tcx>>
-}
-
-impl<'a, 'tcx> VariantInfo<'tcx> {
- pub fn from_ty(tcx: TyCtxt<'a, 'tcx, 'tcx>,
- ty: Ty<'tcx>,
- opt_def: Option<Def>)
- -> Self
- {
- match ty.sty {
- ty::TyAdt(adt, substs) => {
- let variant = match opt_def {
- None => adt.struct_variant(),
- Some(def) => adt.variant_of_def(def)
- };
-
- VariantInfo {
- discr: Disr::from(variant.disr_val),
- fields: variant.fields.iter().map(|f| {
- Field(f.name, monomorphize::field_ty(tcx, substs, f))
- }).collect()
- }
- }
-
- ty::TyTuple(ref v) => {
- VariantInfo {
- discr: Disr(0),
- fields: v.iter().enumerate().map(|(i, &t)| {
- Field(Symbol::intern(&i.to_string()), t)
- }).collect()
- }
- }
-
- _ => {
- bug!("cannot get field types from the type {:?}", ty);
- }
- }
- }
-}
-
/// A structure representing an active landing pad for the duration of a basic
/// block.
///
// Code relating to drop glue.
use std;
+use std::ptr;
use std::iter;
use llvm;
}
ty::TyAdt(adt, substs) => match adt.adt_kind() {
AdtKind::Struct => {
- let VariantInfo { fields, discr } = VariantInfo::from_ty(cx.tcx(), t, None);
- for (i, &Field(_, field_ty)) in fields.iter().enumerate() {
- let mut ptr = ptr.clone();
- ptr.ty = LvalueTy::Downcast {
- adt_def: adt,
- substs: substs,
- variant_index: Disr::from(discr).0 as usize,
- };
- let llfld_a = ptr.trans_field_ptr(&cx, i);
- let ptr = if cx.ccx.shared().type_is_sized(field_ty) {
- LvalueRef::new_sized_ty(llfld_a, field_ty)
- } else {
- LvalueRef::new_unsized_ty(llfld_a, ptr.llextra, field_ty)
- };
- drop_ty(&cx, ptr);
+ for (i, field) in adt.variants[0].fields.iter().enumerate() {
+ let field_ty = monomorphize::field_ty(cx.tcx(), substs, field);
+ let mut field_ptr = ptr.clone();
+ field_ptr.llval = ptr.trans_field_ptr(&cx, i);
+ field_ptr.ty = LvalueTy::from_ty(field_ty);
+ if cx.ccx.shared().type_is_sized(field_ty) {
+ field_ptr.llextra = ptr::null_mut();
+ }
+ drop_ty(&cx, field_ptr);
}
}
AdtKind::Union => {