Skip to content

Commit cd41479

Browse files
committed
Fix the IntTypeExt::to_ty() lifetime bounds
1 parent 76bc6c3 commit cd41479

File tree

7 files changed

+9
-23
lines changed

7 files changed

+9
-23
lines changed

src/librustc/mir/tcx.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use mir::*;
1717
use ty::subst::{Subst, Substs};
1818
use ty::{self, AdtDef, Ty, TyCtxt};
1919
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
20-
use syntax::attr;
2120
use hir;
21+
use ty::util::IntTypeExt;
2222

2323
#[derive(Copy, Clone, Debug)]
2424
pub enum LvalueTy<'tcx> {
@@ -172,13 +172,7 @@ impl<'tcx> Rvalue<'tcx> {
172172
}
173173
Rvalue::Discriminant(ref lval) => {
174174
if let ty::TyAdt(adt_def, _) = lval.ty(mir, tcx).to_ty(tcx).sty {
175-
// FIXME: Why this does not work?
176-
// Some(adt_def.discr_ty.to_ty(tcx))
177-
let ty = match adt_def.discr_ty {
178-
attr::SignedInt(i) => tcx.mk_mach_int(i),
179-
attr::UnsignedInt(i) => tcx.mk_mach_uint(i),
180-
};
181-
Some(ty)
175+
Some(adt_def.discr_ty.to_ty(tcx))
182176
} else {
183177
None
184178
}

src/librustc/ty/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ impl Integer {
454454
/// N.B.: u64 values above i64::MAX will be treated as signed, but
455455
/// that shouldn't affect anything, other than maybe debuginfo.
456456
pub fn repr_discr(tcx: TyCtxt, hints: &[attr::ReprAttr], min: i128, max: i128)
457-
-> (Integer, bool) {
457+
-> (Integer, bool) {
458458
// Theoretically, negative values could be larger in unsigned representation
459459
// than the unsigned representation of the signed minimum. However, if there
460460
// are any negative values, the only valid unsigned representation is u64

src/librustc/ty/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ use rustc_i128::i128;
3939
use hir;
4040

4141
pub trait IntTypeExt {
42-
fn to_ty<'a, 'tcx>(self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx>;
42+
fn to_ty<'a, 'gcx: 'a+'tcx, 'tcx: 'a>(self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx>;
4343
fn disr_incr<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, val: Option<Disr>)
4444
-> Option<Disr>;
4545
fn initial_discriminant<'a, 'tcx>(&self, _: TyCtxt<'a, 'tcx, 'tcx>) -> Disr;
4646
}
4747

4848
impl IntTypeExt for attr::IntType {
49-
fn to_ty<'a, 'gcx, 'tcx>(self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
49+
fn to_ty<'a, 'gcx: 'a+'tcx, 'tcx: 'a>(self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
5050
match self {
5151
SignedInt(i) => tcx.mk_mach_int(i),
5252
UnsignedInt(i) => tcx.mk_mach_uint(i),

src/librustc_borrowck/borrowck/mir/elaborate_drops.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,6 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
706706
switch_ty: discr_ty,
707707
values: From::from(values),
708708
targets: blocks,
709-
// adt_def: adt,
710-
// targets: variant_drops
711709
}
712710
}),
713711
is_cleanup: c.is_cleanup,

src/librustc_mir/build/matches/test.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ use rustc_data_structures::fx::FxHashMap;
2222
use rustc_data_structures::bitvec::BitVector;
2323
use rustc::middle::const_val::{ConstVal, ConstInt};
2424
use rustc::ty::{self, Ty};
25+
use rustc::ty::util::IntTypeExt;
2526
use rustc::mir::*;
2627
use rustc::hir::RangeEnd;
2728
use syntax_pos::Span;
28-
use syntax::attr;
2929
use std::cmp::Ordering;
3030

3131
impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
@@ -212,13 +212,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
212212
}
213213
debug!("num_enum_variants: {}, tested variants: {:?}, variants: {:?}",
214214
num_enum_variants, values, variants);
215-
// FIXME: WHY THIS DOES NOT WORK?!
216-
// let discr_ty = adt_def.discr_ty.to_ty(tcx);
217-
let discr_ty = match adt_def.discr_ty {
218-
attr::SignedInt(i) => tcx.mk_mach_int(i),
219-
attr::UnsignedInt(i) => tcx.mk_mach_uint(i),
220-
};
221-
215+
let discr_ty = adt_def.discr_ty.to_ty(tcx);
222216
let discr = self.temp(discr_ty);
223217
self.cfg.push_assign(block, source_info, &discr,
224218
Rvalue::Discriminant(lvalue.clone()));

src/librustc_trans/mir/rvalue.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,6 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
434434
let enum_ty = discr_lvalue.ty.to_ty(bcx.tcx());
435435
let discr_ty = rvalue.ty(&*self.mir, bcx.tcx()).unwrap();
436436
let discr_type = type_of::immediate_type_of(bcx.ccx, discr_ty);
437-
// FIXME: inline this
438437
let discr = adt::trans_get_discr(&bcx, enum_ty, discr_lvalue.llval, None, true);
439438
let discr = if common::val_ty(discr) == Type::i1(bcx.ccx) {
440439
bcx.zext(discr, discr_type)

src/librustc_typeck/collect.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,8 @@ fn evaluate_disr_expr(ccx: &CrateCtxt, repr_ty: attr::IntType, body: hir::BodyId
10451045
let hint = UncheckedExprHint(ty_hint);
10461046
match ConstContext::new(ccx.tcx, body).eval(e, hint) {
10471047
Ok(ConstVal::Integral(i)) => {
1048-
// FIXME: eval should return an error if the hint is wrong
1048+
// FIXME: eval should return an error if the hint does not match the type of the body.
1049+
// i.e. eventually the match below would not exist.
10491050
match (repr_ty, i) {
10501051
(attr::SignedInt(ast::IntTy::I8), ConstInt::I8(_)) |
10511052
(attr::SignedInt(ast::IntTy::I16), ConstInt::I16(_)) |

0 commit comments

Comments
 (0)