diff --git a/src/librustc_trans/trans/adt.rs b/src/librustc_trans/trans/adt.rs index 2fb0488cd704e04b8912da4d3a89523117d4eb7a..1525055f13fde09550bc46328e7428912f984979 100644 --- a/src/librustc_trans/trans/adt.rs +++ b/src/librustc_trans/trans/adt.rs @@ -778,7 +778,9 @@ fn load_discr(bcx: Block, ity: IntType, ptr: ValueRef, min: Disr, max: Disr) assert!(bits <= 64); let bits = bits as uint; let mask = (-1u64 >> (64 - bits)) as Disr; - if (max + 1) & mask == min & mask { + // For a (max) discr of -1, max will be `-1 as usize`, which overflows. + // However, that is fine here (it would still represent the full range), + if (max.wrapping_add(1)) & mask == min & mask { // i.e., if the range is everything. The lo==hi case would be // rejected by the LLVM verifier (it would mean either an // empty set, which is impossible, or the entire range of the @@ -787,7 +789,7 @@ fn load_discr(bcx: Block, ity: IntType, ptr: ValueRef, min: Disr, max: Disr) } else { // llvm::ConstantRange can deal with ranges that wrap around, // so an overflow on (max + 1) is fine. - LoadRangeAssert(bcx, ptr, min, (max+1), /* signed: */ True) + LoadRangeAssert(bcx, ptr, min, (max.wrapping_add(1)), /* signed: */ True) } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index d9dc050aebf10d13e251f192e9f9113187b9af79..87c17c7d9ad9b2aa7cdd0d62624a921117519034 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -205,9 +205,9 @@ pub fn opt_ast_region_to_region<'tcx>( if len == 2 && i == 0 { m.push_str(" or "); - } else if i == len - 2 { + } else if i + 2 == len { m.push_str(", or "); - } else if i != len - 1 { + } else if i + 1 != len { m.push_str(", "); } } diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index 94b7d1b4d8cb0658c115a2daf86ab2c32298bbd6..17687534d750ae81376d2f95effc99541e102344 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -181,7 +181,6 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span, Struct(ref fields) => { let emit_struct_field = cx.ident_of("emit_struct_field"); let mut stmts = Vec::new(); - let last = fields.len() - 1; for (i, &FieldInfo { name, ref self_, @@ -204,6 +203,7 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span, lambda)); // last call doesn't need a try! + let last = fields.len() - 1; let call = if i != last { cx.expr_try(span, call) } else {