Fix the IntTypeExt::to_ty() lifetime bounds

This commit is contained in:
Simonas Kazlauskas 2017-02-02 19:53:44 +02:00
parent 64182a587c
commit c9939863ca
7 changed files with 9 additions and 59 deletions

View File

@ -17,8 +17,8 @@ use mir::*;
use ty::subst::{Subst, Substs};
use ty::{self, AdtDef, Ty, TyCtxt};
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
use syntax::attr;
use hir;
use ty::util::IntTypeExt;
#[derive(Copy, Clone, Debug)]
pub enum LvalueTy<'tcx> {
@ -172,13 +172,7 @@ impl<'tcx> Rvalue<'tcx> {
}
Rvalue::Discriminant(ref lval) => {
if let ty::TyAdt(adt_def, _) = lval.ty(mir, tcx).to_ty(tcx).sty {
// FIXME: Why this does not work?
// Some(adt_def.discr_ty.to_ty(tcx))
let ty = match adt_def.discr_ty {
attr::SignedInt(i) => tcx.mk_mach_int(i),
attr::UnsignedInt(i) => tcx.mk_mach_uint(i),
};
Some(ty)
Some(adt_def.discr_ty.to_ty(tcx))
} else {
None
}

View File

@ -453,13 +453,8 @@ impl Integer {
/// signed discriminant range and #[repr] attribute.
/// N.B.: u64 values above i64::MAX will be treated as signed, but
/// that shouldn't affect anything, other than maybe debuginfo.
<<<<<<< HEAD
fn repr_discr(tcx: TyCtxt, ty: Ty, repr: &ReprOptions, min: i64, max: i64)
fn repr_discr(tcx: TyCtxt, ty: Ty, repr: &ReprOptions, min: i128, max: i128)
-> (Integer, bool) {
=======
pub fn repr_discr(tcx: TyCtxt, hints: &[attr::ReprAttr], min: i128, max: i128)
-> (Integer, bool) {
>>>>>>> cade130ae8... AdtDef now contains discr_ty same as layouted
// Theoretically, negative values could be larger in unsigned representation
// than the unsigned representation of the signed minimum. However, if there
// are any negative values, the only valid unsigned representation is u64
@ -470,7 +465,6 @@ impl Integer {
let mut min_from_extern = None;
let min_default = I8;
<<<<<<< HEAD
if let Some(ity) = repr.int {
let discr = Integer::from_attr(&tcx.data_layout, ity);
let fit = if ity.is_signed() { signed_fit } else { unsigned_fit };
@ -489,36 +483,6 @@ impl Integer {
// lower bound. However, we don't run on those yet...?
"arm" => min_from_extern = Some(I32),
_ => min_from_extern = Some(I32),
=======
for &r in hints.iter() {
match r {
attr::ReprInt(ity) => {
let discr = Integer::from_attr(&tcx.data_layout, ity);
let fit = if ity.is_signed() { signed_fit } else { unsigned_fit };
if discr < fit {
bug!("Integer::repr_discr: `#[repr]` hint too small for \
discriminant range of enum")
}
return (discr, ity.is_signed());
}
attr::ReprExtern => {
match &tcx.sess.target.target.arch[..] {
// WARNING: the ARM EABI has two variants; the one corresponding
// to `at_least == I32` appears to be used on Linux and NetBSD,
// but some systems may use the variant corresponding to no
// lower bound. However, we don't run on those yet...?
"arm" => min_from_extern = Some(I32),
_ => min_from_extern = Some(I32),
}
}
attr::ReprAny => {},
attr::ReprPacked => {
bug!("Integer::repr_discr: found #[repr(packed)] on enum");
}
attr::ReprSimd => {
bug!("Integer::repr_discr: found #[repr(simd)] on enum");
}
>>>>>>> cade130ae8... AdtDef now contains discr_ty same as layouted
}
}

View File

@ -39,14 +39,14 @@ use rustc_i128::i128;
use hir;
pub trait IntTypeExt {
fn to_ty<'a, 'tcx>(self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx>;
fn to_ty<'a, 'gcx: 'a+'tcx, 'tcx: 'a>(self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx>;
fn disr_incr<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, val: Option<Disr>)
-> Option<Disr>;
fn initial_discriminant<'a, 'tcx>(&self, _: TyCtxt<'a, 'tcx, 'tcx>) -> Disr;
}
impl IntTypeExt for attr::IntType {
fn to_ty<'a, 'gcx, 'tcx>(self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
fn to_ty<'a, 'gcx: 'a+'tcx, 'tcx: 'a>(self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
match self {
SignedInt(i) => tcx.mk_mach_int(i),
UnsignedInt(i) => tcx.mk_mach_uint(i),

View File

@ -706,8 +706,6 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
switch_ty: discr_ty,
values: From::from(values),
targets: blocks,
// adt_def: adt,
// targets: variant_drops
}
}),
is_cleanup: c.is_cleanup,

View File

@ -22,10 +22,10 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::bitvec::BitVector;
use rustc::middle::const_val::{ConstVal, ConstInt};
use rustc::ty::{self, Ty};
use rustc::ty::util::IntTypeExt;
use rustc::mir::*;
use rustc::hir::RangeEnd;
use syntax_pos::Span;
use syntax::attr;
use std::cmp::Ordering;
impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
@ -212,13 +212,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
}
debug!("num_enum_variants: {}, tested variants: {:?}, variants: {:?}",
num_enum_variants, values, variants);
// FIXME: WHY THIS DOES NOT WORK?!
// let discr_ty = adt_def.discr_ty.to_ty(tcx);
let discr_ty = match adt_def.discr_ty {
attr::SignedInt(i) => tcx.mk_mach_int(i),
attr::UnsignedInt(i) => tcx.mk_mach_uint(i),
};
let discr_ty = adt_def.discr_ty.to_ty(tcx);
let discr = self.temp(discr_ty);
self.cfg.push_assign(block, source_info, &discr,
Rvalue::Discriminant(lvalue.clone()));

View File

@ -438,7 +438,6 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
let enum_ty = discr_lvalue.ty.to_ty(bcx.tcx());
let discr_ty = rvalue.ty(&*self.mir, bcx.tcx()).unwrap();
let discr_type = type_of::immediate_type_of(bcx.ccx, discr_ty);
// FIXME: inline this
let discr = adt::trans_get_discr(&bcx, enum_ty, discr_lvalue.llval, None, true);
let discr = if common::val_ty(discr) == Type::i1(bcx.ccx) {
bcx.zext(discr, discr_type)

View File

@ -1047,7 +1047,8 @@ fn evaluate_disr_expr(ccx: &CrateCtxt, repr_ty: attr::IntType, body: hir::BodyId
let hint = UncheckedExprHint(ty_hint);
match ConstContext::new(ccx.tcx, body).eval(e, hint) {
Ok(ConstVal::Integral(i)) => {
// FIXME: eval should return an error if the hint is wrong
// FIXME: eval should return an error if the hint does not match the type of the body.
// i.e. eventually the match below would not exist.
match (repr_ty, i) {
(attr::SignedInt(ast::IntTy::I8), ConstInt::I8(_)) |
(attr::SignedInt(ast::IntTy::I16), ConstInt::I16(_)) |