about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSimonas Kazlauskas <git@kazlauskas.me>2017-02-02 19:53:44 +0200
committerSimonas Kazlauskas <git@kazlauskas.me>2017-02-10 19:43:57 +0200
commitc9939863ca5983614e8e70e0abdb088af60ac590 (patch)
tree1b3bc2099ac9934898970836c06f5d1693ed6d1c
parent64182a587c0c26559b166cbf45ab33f10b332ffc (diff)
downloadrust-c9939863ca5983614e8e70e0abdb088af60ac590.tar.gz
rust-c9939863ca5983614e8e70e0abdb088af60ac590.zip
Fix the IntTypeExt::to_ty() lifetime bounds
-rw-r--r--src/librustc/mir/tcx.rs10
-rw-r--r--src/librustc/ty/layout.rs38
-rw-r--r--src/librustc/ty/util.rs4
-rw-r--r--src/librustc_borrowck/borrowck/mir/elaborate_drops.rs2
-rw-r--r--src/librustc_mir/build/matches/test.rs10
-rw-r--r--src/librustc_trans/mir/rvalue.rs1
-rw-r--r--src/librustc_typeck/collect.rs3
7 files changed, 9 insertions, 59 deletions
diff --git a/src/librustc/mir/tcx.rs b/src/librustc/mir/tcx.rs
index fcfd1c57672..6863468ec0d 100644
--- a/src/librustc/mir/tcx.rs
+++ b/src/librustc/mir/tcx.rs
@@ -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
                 }
diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs
index 3a7acc5c7b5..70ae799d350 100644
--- a/src/librustc/ty/layout.rs
+++ b/src/librustc/ty/layout.rs
@@ -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
             }
         }
 
diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs
index fe4b6dad30e..0281e53427d 100644
--- a/src/librustc/ty/util.rs
+++ b/src/librustc/ty/util.rs
@@ -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),
diff --git a/src/librustc_borrowck/borrowck/mir/elaborate_drops.rs b/src/librustc_borrowck/borrowck/mir/elaborate_drops.rs
index 53e84f1fb71..7521b750d5a 100644
--- a/src/librustc_borrowck/borrowck/mir/elaborate_drops.rs
+++ b/src/librustc_borrowck/borrowck/mir/elaborate_drops.rs
@@ -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,
diff --git a/src/librustc_mir/build/matches/test.rs b/src/librustc_mir/build/matches/test.rs
index f2d48f65fef..d9c2e6bb090 100644
--- a/src/librustc_mir/build/matches/test.rs
+++ b/src/librustc_mir/build/matches/test.rs
@@ -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()));
diff --git a/src/librustc_trans/mir/rvalue.rs b/src/librustc_trans/mir/rvalue.rs
index fe11e0426df..0810bfcadca 100644
--- a/src/librustc_trans/mir/rvalue.rs
+++ b/src/librustc_trans/mir/rvalue.rs
@@ -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)
diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs
index 30bd22454e7..2f8258ef616 100644
--- a/src/librustc_typeck/collect.rs
+++ b/src/librustc_typeck/collect.rs
@@ -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(_)) |