|
1 |
| -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT |
| 1 | +// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT |
2 | 2 | // file at the top-level directory of this distribution and at
|
3 | 3 | // http://rust-lang.org/COPYRIGHT.
|
4 | 4 | //
|
@@ -34,7 +34,7 @@ use std::borrow::{Cow, IntoCow};
|
34 | 34 | use std::num::wrapping::OverflowingOps;
|
35 | 35 | use std::cmp::Ordering;
|
36 | 36 | use std::collections::hash_map::Entry::Vacant;
|
37 |
| -use std::{i8, i16, i32, i64}; |
| 37 | +use std::{i8, i16, i32, i64, u8, u16, u32, u64}; |
38 | 38 | use std::rc::Rc;
|
39 | 39 |
|
40 | 40 | fn lookup_const<'a>(tcx: &'a ty::ctxt, e: &Expr) -> Option<&'a Expr> {
|
@@ -461,6 +461,16 @@ pub fn const_uint_checked_neg<'a>(
|
461 | 461 | Ok(const_uint((!a).wrapping_add(1)))
|
462 | 462 | }
|
463 | 463 |
|
| 464 | +fn const_uint_not(a: u64, opt_ety: Option<UintTy>) -> const_val { |
| 465 | + let mask = match opt_ety { |
| 466 | + Some(UintTy::U8) => u8::MAX as u64, |
| 467 | + Some(UintTy::U16) => u16::MAX as u64, |
| 468 | + Some(UintTy::U32) => u32::MAX as u64, |
| 469 | + None | Some(UintTy::U64) => u64::MAX, |
| 470 | + }; |
| 471 | + const_uint(!a & mask) |
| 472 | +} |
| 473 | + |
464 | 474 | macro_rules! overflow_checking_body {
|
465 | 475 | ($a:ident, $b:ident, $ety:ident, $overflowing_op:ident,
|
466 | 476 | lhs: $to_8_lhs:ident $to_16_lhs:ident $to_32_lhs:ident,
|
@@ -677,7 +687,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
|
677 | 687 | ast::ExprUnary(ast::UnNot, ref inner) => {
|
678 | 688 | match try!(eval_const_expr_partial(tcx, &**inner, ety)) {
|
679 | 689 | const_int(i) => const_int(!i),
|
680 |
| - const_uint(i) => const_uint(!i), |
| 690 | + const_uint(i) => const_uint_not(i, expr_uint_type), |
681 | 691 | const_bool(b) => const_bool(!b),
|
682 | 692 | const_str(_) => signal!(e, NotOnString),
|
683 | 693 | const_float(_) => signal!(e, NotOnFloat),
|
|
0 commit comments