Skip to content
Permalink
Browse files

fallout from new approach where both sides must be known

  • Loading branch information...
nikomatsakis committed Mar 24, 2015
1 parent 7eb6914 commit 2b96c792d27c6f0c18221cbd620fe2f6862c1c08
@@ -105,8 +105,8 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
_ => ()
}

let _0: T = Float::zero();
let _1: T = Float::one();
let _0 = T::zero();
let _1 = T::one();

match num.classify() {
Fp::Nan => return f("NaN"),
@@ -119,7 +119,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
_ => {}
}

let neg = num < _0 || (negative_zero && _1 / num == Float::neg_infinity());
let neg = num < _0 || (negative_zero && _1 / num == T::neg_infinity());
// For an f64 the exponent is in the range of [-1022, 1023] for base 2, so
// we may have up to that many digits. Give ourselves some extra wiggle room
// otherwise as well.
@@ -36,11 +36,11 @@ trait GenericRadix {
fn fmt_int<T: Int>(&self, mut x: T, f: &mut fmt::Formatter) -> fmt::Result {
// The radix can be as low as 2, so we need a buffer of at least 64
// characters for a base 2 number.
let zero = Int::zero();
let zero = T::zero();
let is_positive = x >= zero;
let mut buf = [0; 64];
let mut curr = buf.len();
let base = cast(self.base()).unwrap();
let base: T = cast(self.base()).unwrap();
if is_positive {
// Accumulate each digit of the number from the least significant
// to the most significant figure.
@@ -2615,7 +2615,7 @@ pub struct RangeStep<A> {
#[unstable(feature = "core",
reason = "likely to be replaced by range notation and adapters")]
pub fn range_step<A: Int>(start: A, stop: A, step: A) -> RangeStep<A> {
let rev = step < Int::zero();
let rev = step < A::zero();
RangeStep{state: start, stop: stop, step: step, rev: rev}
}

@@ -2679,7 +2679,7 @@ pub struct RangeStepInclusive<A> {
#[unstable(feature = "core",
reason = "likely to be replaced by range notation and adapters")]
pub fn range_step_inclusive<A: Int>(start: A, stop: A, step: A) -> RangeStepInclusive<A> {
let rev = step < Int::zero();
let rev = step < A::zero();
RangeStepInclusive {
state: start,
stop: stop,
@@ -2725,7 +2725,7 @@ impl<A: Int> Iterator for ::ops::Range<A> {
fn next(&mut self) -> Option<A> {
if self.start < self.end {
let result = self.start;
self.start = self.start + Int::one();
self.start = self.start + A::one();
Some(result)
} else {
None
@@ -2752,7 +2752,7 @@ impl<A: Int> DoubleEndedIterator for ::ops::Range<A> {
#[inline]
fn next_back(&mut self) -> Option<A> {
if self.start < self.end {
self.end = self.end - Int::one();
self.end = self.end - A::one();
Some(self.end)
} else {
None
@@ -2767,7 +2767,7 @@ impl<A: Int> Iterator for ::ops::RangeFrom<A> {
#[inline]
fn next(&mut self) -> Option<A> {
let result = self.start;
self.start = self.start + Int::one();
self.start = self.start + A::one();
debug_assert!(result < self.start);
Some(result)
}
@@ -158,7 +158,7 @@ impl Float for f32 {
/// Returns `true` if the number is infinite.
#[inline]
fn is_infinite(self) -> bool {
self == Float::infinity() || self == Float::neg_infinity()
self == f32::infinity() || self == f32::neg_infinity()
}

/// Returns `true` if the number is neither infinite or NaN.
@@ -290,39 +290,39 @@ impl Float for f32 {
#[inline]
fn fract(self) -> f32 { self - self.trunc() }

/// Computes the absolute value of `self`. Returns `Float::nan()` if the
/// number is `Float::nan()`.
/// Computes the absolute value of `self`. Returns `f32::nan()` if the
/// number is `f32::nan()`.
#[inline]
fn abs(self) -> f32 {
unsafe { intrinsics::fabsf32(self) }
}

/// Returns a number that represents the sign of `self`.
///
/// - `1.0` if the number is positive, `+0.0` or `Float::infinity()`
/// - `-1.0` if the number is negative, `-0.0` or `Float::neg_infinity()`
/// - `Float::nan()` if the number is `Float::nan()`
/// - `1.0` if the number is positive, `+0.0` or `f32::infinity()`
/// - `-1.0` if the number is negative, `-0.0` or `f32::neg_infinity()`
/// - `f32::nan()` if the number is `f32::nan()`
#[inline]
fn signum(self) -> f32 {
if self.is_nan() {
Float::nan()
f32::nan()
} else {
unsafe { intrinsics::copysignf32(1.0, self) }
}
}

/// Returns `true` if `self` is positive, including `+0.0` and
/// `Float::infinity()`.
/// `f32::infinity()`.
#[inline]
fn is_positive(self) -> bool {
self > 0.0 || (1.0 / self) == Float::infinity()
self > 0.0 || (1.0 / self) == f32::infinity()
}

/// Returns `true` if `self` is negative, including `-0.0` and
/// `Float::neg_infinity()`.
/// `f32::neg_infinity()`.
#[inline]
fn is_negative(self) -> bool {
self < 0.0 || (1.0 / self) == Float::neg_infinity()
self < 0.0 || (1.0 / self) == f32::neg_infinity()
}

/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
@@ -165,7 +165,7 @@ impl Float for f64 {
/// Returns `true` if the number is infinite.
#[inline]
fn is_infinite(self) -> bool {
self == Float::infinity() || self == Float::neg_infinity()
self == f64::infinity() || self == f64::neg_infinity()
}

/// Returns `true` if the number is neither infinite or NaN.
@@ -297,39 +297,39 @@ impl Float for f64 {
#[inline]
fn fract(self) -> f64 { self - self.trunc() }

/// Computes the absolute value of `self`. Returns `Float::nan()` if the
/// number is `Float::nan()`.
/// Computes the absolute value of `self`. Returns `f64::nan()` if the
/// number is `f64::nan()`.
#[inline]
fn abs(self) -> f64 {
unsafe { intrinsics::fabsf64(self) }
}

/// Returns a number that represents the sign of `self`.
///
/// - `1.0` if the number is positive, `+0.0` or `Float::infinity()`
/// - `-1.0` if the number is negative, `-0.0` or `Float::neg_infinity()`
/// - `Float::nan()` if the number is `Float::nan()`
/// - `1.0` if the number is positive, `+0.0` or `f64::infinity()`
/// - `-1.0` if the number is negative, `-0.0` or `f64::neg_infinity()`
/// - `f64::nan()` if the number is `f64::nan()`
#[inline]
fn signum(self) -> f64 {
if self.is_nan() {
Float::nan()
f64::nan()
} else {
unsafe { intrinsics::copysignf64(1.0, self) }
}
}

/// Returns `true` if `self` is positive, including `+0.0` and
/// `Float::infinity()`.
/// `f64::infinity()`.
#[inline]
fn is_positive(self) -> bool {
self > 0.0 || (1.0 / self) == Float::infinity()
self > 0.0 || (1.0 / self) == f64::infinity()
}

/// Returns `true` if `self` is negative, including `-0.0` and
/// `Float::neg_infinity()`.
/// `f64::neg_infinity()`.
#[inline]
fn is_negative(self) -> bool {
self < 0.0 || (1.0 / self) == Float::neg_infinity()
self < 0.0 || (1.0 / self) == f64::neg_infinity()
}

/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
@@ -349,9 +349,9 @@ pub trait Int
#[inline]
fn saturating_add(self, other: Self) -> Self {
match self.checked_add(other) {
Some(x) => x,
None if other >= Int::zero() => Int::max_value(),
None => Int::min_value(),
Some(x) => x,
None if other >= Self::zero() => Self::max_value(),
None => Self::min_value(),
}
}

@@ -361,9 +361,9 @@ pub trait Int
#[inline]
fn saturating_sub(self, other: Self) -> Self {
match self.checked_sub(other) {
Some(x) => x,
None if other >= Int::zero() => Int::min_value(),
None => Int::max_value(),
Some(x) => x,
None if other >= Self::zero() => Self::min_value(),
None => Self::max_value(),
}
}

@@ -381,7 +381,7 @@ pub trait Int
#[inline]
fn pow(self, mut exp: u32) -> Self {
let mut base = self;
let mut acc: Self = Int::one();
let mut acc: Self = Self::one();

let mut prev_base = self;
let mut base_oflo = false;
@@ -565,7 +565,7 @@ macro_rules! int_impl {
fn min_value() -> $T { (-1 as $T) << ($BITS - 1) }

#[inline]
fn max_value() -> $T { let min: $T = Int::min_value(); !min }
fn max_value() -> $T { let min = <$T>::min_value(); !min }

#[inline]
fn count_ones(self) -> u32 { (self as $UnsignedT).count_ones() }
@@ -604,7 +604,7 @@ macro_rules! int_impl {
fn checked_div(self, v: $T) -> Option<$T> {
match v {
0 => None,
-1 if self == Int::min_value()
-1 if self == <$T>::min_value()
=> None,
v => Some(self / v),
}
@@ -715,7 +715,7 @@ pub trait UnsignedInt: Int + WrappingOps {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
fn is_power_of_two(self) -> bool {
(self.wrapping_sub(Int::one())) & self == Int::zero() && !(self == Int::zero())
(self.wrapping_sub(Int::one())) & self == Self::zero() && !(self == Self::zero())
}

/// Returns the smallest power of two greater than or equal to `self`.
@@ -866,8 +866,8 @@ macro_rules! impl_to_primitive_int_to_int {
macro_rules! impl_to_primitive_int_to_uint {
($SrcT:ty, $DstT:ty, $slf:expr) => (
{
let zero: $SrcT = Int::zero();
let max_value: $DstT = Int::max_value();
let zero= <$SrcT>::zero();
let max_value = <$DstT>::max_value();
if zero <= $slf && $slf as u64 <= max_value as u64 {
Some($slf as $DstT)
} else {
@@ -939,8 +939,8 @@ macro_rules! impl_to_primitive_uint_to_uint {
if size_of::<$SrcT>() <= size_of::<$DstT>() {
Some($slf as $DstT)
} else {
let zero: $SrcT = Int::zero();
let max_value: $DstT = Int::max_value();
let zero = <$SrcT>::zero();
let max_value = <$DstT>::max_value();
if zero <= $slf && $slf as u64 <= max_value as u64 {
Some($slf as $DstT)
} else {
@@ -1751,7 +1751,7 @@ macro_rules! from_str_radix_int_impl {
"from_str_radix_int: must lie in the range `[2, 36]` - found {}",
radix);

let is_signed_ty = (0 as $T) > Int::min_value();
let is_signed_ty = (0 as $T) > <$T>::min_value();

match src.slice_shift_char() {
Some(('-', "")) => Err(PIE { kind: Empty }),
@@ -64,7 +64,7 @@ impl ToBits for u64 {
fn add_bytes_to_bits<T: Int + ToBits>(bits: T, bytes: T) -> T {
let (new_high_bits, new_low_bits) = bytes.to_bits();

if new_high_bits > Int::zero() {
if new_high_bits > T::zero() {
panic!("numeric overflow occurred.")
}

@@ -87,7 +87,7 @@ use syntax::attr::AttrMetaMethods;
use syntax::ext::mtwt;
use syntax::parse::token::{self, special_names, special_idents};
use syntax::ptr::P;
use syntax::codemap::{self, Span, Pos};
use syntax::codemap::{self, BytePos, Span, Pos};
use syntax::visit::{self, Visitor};

use std::collections::{HashMap, HashSet};
@@ -1967,7 +1967,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
let module_name = self.module_to_string(&*search_module);
let mut span = span;
let msg = if "???" == &module_name[..] {
span.hi = span.lo + Pos::from_usize(segment_name.len());
span.hi = span.lo + BytePos::from_usize(segment_name.len());

match search_parent_externals(name,
&self.current_module) {
@@ -216,7 +216,7 @@ pub fn float_to_str_bytes_common<T: Float>(
_ => {}
}

let neg = num < _0 || (negative_zero && _1 / num == Float::neg_infinity());
let neg = num < _0 || (negative_zero && _1 / num == T::neg_infinity());
let mut buf = Vec::new();
let radix_gen: T = num::cast(radix as int).unwrap();

@@ -68,7 +68,7 @@ pub fn unimpl() -> IoError {

// unix has nonzero values as errors
pub fn mkerr_libc<T: Int>(ret: T) -> IoResult<()> {
if ret != Int::zero() {
if ret != T::zero() {
Err(last_error())
} else {
Ok(())
@@ -1005,7 +1005,7 @@ pub enum Sign {

impl Sign {
pub fn new<T:Int>(n: T) -> Sign {
if n < Int::zero() {
if n < T::zero() {
Minus
} else {
Plus
@@ -582,8 +582,8 @@ impl CodeMap {
Some(last) => last.end_pos.to_usize(),
};

let end_pos = Pos::from_usize(start_pos + source_len);
let start_pos = Pos::from_usize(start_pos);
let end_pos = BytePos::from_usize(start_pos + source_len);
let start_pos = BytePos::from_usize(start_pos);

let lines = file_local_lines.map_in_place(|pos| pos + start_pos);
let multibyte_chars = file_local_multibyte_chars.map_in_place(|mbc| MultiByteChar {
@@ -13,7 +13,7 @@ use ast::{Ident, Generics, Expr};
use ast;
use ast_util;
use attr;
use codemap::{Span, respan, Spanned, DUMMY_SP, Pos};
use codemap::{BytePos, Span, respan, Spanned, DUMMY_SP, Pos};
use ext::base::ExtCtxt;
use owned_slice::OwnedSlice;
use parse::token::special_idents;
@@ -633,7 +633,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
fn expr_field_access(&self, sp: Span, expr: P<ast::Expr>, ident: ast::Ident) -> P<ast::Expr> {
let field_name = token::get_ident(ident);
let field_span = Span {
lo: sp.lo - Pos::from_usize(field_name.len()),
lo: sp.lo - BytePos::from_usize(field_name.len()),
hi: sp.hi,
expn_id: sp.expn_id,
};
@@ -643,7 +643,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
}
fn expr_tup_field_access(&self, sp: Span, expr: P<ast::Expr>, idx: usize) -> P<ast::Expr> {
let field_span = Span {
lo: sp.lo - Pos::from_usize(idx.to_string().len()),
lo: sp.lo - BytePos::from_usize(idx.to_string().len()),
hi: sp.hi,
expn_id: sp.expn_id,
};
@@ -337,7 +337,7 @@ impl<'a> StringReader<'a> {
let last_char = self.curr.unwrap();
let next = self.source_text.char_range_at(current_byte_offset);
let byte_offset_diff = next.next - current_byte_offset;
self.pos = self.pos + Pos::from_usize(byte_offset_diff);
self.pos = self.pos + BytePos::from_usize(byte_offset_diff);
self.curr = Some(next.ch);
self.col = self.col + CharPos(1);
if last_char == '\n' {
Oops, something went wrong.

0 comments on commit 2b96c79

Please sign in to comment.
You can’t perform that action at this time.