Skip to content

Commit 93f6c4e

Browse files
committed
---
yaml --- r: 166456 b: refs/heads/snap-stage3 c: 21ea66f h: refs/heads/master v: v3
1 parent 7c1eb2c commit 93f6c4e

File tree

17 files changed

+240
-174
lines changed

17 files changed

+240
-174
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 18842f89f084c52588fe7cffe07f87bf6e90796a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 96a3c7c6a051ab2f5fc01fe9e686f7fffcc87c61
4+
refs/heads/snap-stage3: 21ea66f47ad059279628736b31a3a8bddd2710d3
55
refs/heads/try: f5d619caf9f32458680fae55526b99582ca682dd
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/libcore/fmt/float.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use char;
1818
use char::Char;
1919
use fmt;
2020
use iter::{range, DoubleEndedIteratorExt};
21-
use num::{cast, Float, ToPrimitive};
22-
use num::FpCategory as Fp;
21+
use num::{Float, FPNaN, FPInfinite, ToPrimitive};
22+
use num::cast;
2323
use ops::FnOnce;
2424
use result::Result::Ok;
2525
use slice::{mod, SliceExt};
@@ -109,11 +109,11 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
109109
let _1: T = Float::one();
110110

111111
match num.classify() {
112-
Fp::Nan => return f("NaN".as_bytes()),
113-
Fp::Infinite if num > _0 => {
112+
FPNaN => return f("NaN".as_bytes()),
113+
FPInfinite if num > _0 => {
114114
return f("inf".as_bytes());
115115
}
116-
Fp::Infinite if num < _0 => {
116+
FPInfinite if num < _0 => {
117117
return f("-inf".as_bytes());
118118
}
119119
_ => {}

branches/snap-stage3/src/libcore/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#![allow(unknown_features, raw_pointer_deriving)]
6060
#![feature(globs, intrinsics, lang_items, macro_rules, phase)]
6161
#![feature(simd, unsafe_destructor, slicing_syntax)]
62-
#![feature(default_type_params, unboxed_closures)]
62+
#![feature(default_type_params, unboxed_closures, associated_types)]
6363
#![deny(missing_docs)]
6464

6565
mod macros;

branches/snap-stage3/src/libcore/num/f32.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
use intrinsics;
2020
use mem;
21-
use num::Float;
22-
use num::FpCategory as Fp;
21+
use num::{Float, FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};
2322
use num::from_str_radix;
2423
use option::Option;
2524

@@ -157,23 +156,23 @@ impl Float for f32 {
157156
/// Returns `true` if the number is neither zero, infinite, subnormal or NaN.
158157
#[inline]
159158
fn is_normal(self) -> bool {
160-
self.classify() == Fp::Normal
159+
self.classify() == FPNormal
161160
}
162161

163162
/// Returns the floating point category of the number. If only one property
164163
/// is going to be tested, it is generally faster to use the specific
165164
/// predicate instead.
166-
fn classify(self) -> Fp {
165+
fn classify(self) -> FPCategory {
167166
const EXP_MASK: u32 = 0x7f800000;
168167
const MAN_MASK: u32 = 0x007fffff;
169168

170169
let bits: u32 = unsafe { mem::transmute(self) };
171170
match (bits & MAN_MASK, bits & EXP_MASK) {
172-
(0, 0) => Fp::Zero,
173-
(_, 0) => Fp::Subnormal,
174-
(0, EXP_MASK) => Fp::Infinite,
175-
(_, EXP_MASK) => Fp::Nan,
176-
_ => Fp::Normal,
171+
(0, 0) => FPZero,
172+
(_, 0) => FPSubnormal,
173+
(0, EXP_MASK) => FPInfinite,
174+
(_, EXP_MASK) => FPNaN,
175+
_ => FPNormal,
177176
}
178177
}
179178

branches/snap-stage3/src/libcore/num/f64.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
use intrinsics;
2020
use mem;
21-
use num::Float;
22-
use num::FpCategory as Fp;
21+
use num::{Float, FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};
2322
use num::from_str_radix;
2423
use option::Option;
2524

@@ -165,23 +164,23 @@ impl Float for f64 {
165164
/// Returns `true` if the number is neither zero, infinite, subnormal or NaN.
166165
#[inline]
167166
fn is_normal(self) -> bool {
168-
self.classify() == Fp::Normal
167+
self.classify() == FPNormal
169168
}
170169

171170
/// Returns the floating point category of the number. If only one property
172171
/// is going to be tested, it is generally faster to use the specific
173172
/// predicate instead.
174-
fn classify(self) -> Fp {
173+
fn classify(self) -> FPCategory {
175174
const EXP_MASK: u64 = 0x7ff0000000000000;
176175
const MAN_MASK: u64 = 0x000fffffffffffff;
177176

178177
let bits: u64 = unsafe { mem::transmute(self) };
179178
match (bits & MAN_MASK, bits & EXP_MASK) {
180-
(0, 0) => Fp::Zero,
181-
(_, 0) => Fp::Subnormal,
182-
(0, EXP_MASK) => Fp::Infinite,
183-
(_, EXP_MASK) => Fp::Nan,
184-
_ => Fp::Normal,
179+
(0, 0) => FPZero,
180+
(_, 0) => FPSubnormal,
181+
(0, EXP_MASK) => FPInfinite,
182+
(_, EXP_MASK) => FPNaN,
183+
_ => FPNormal,
185184
}
186185
}
187186

branches/snap-stage3/src/libcore/num/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#![stable]
1616
#![allow(missing_docs)]
1717

18+
pub use self::FPCategory::*;
19+
1820
use {int, i8, i16, i32, i64};
1921
use {uint, u8, u16, u32, u64};
2022
use {f32, f64};
@@ -1220,17 +1222,17 @@ impl_num_cast! { f64, to_f64 }
12201222
/// Used for representing the classification of floating point numbers
12211223
#[deriving(Copy, PartialEq, Show)]
12221224
#[unstable = "may be renamed"]
1223-
pub enum FpCategory {
1225+
pub enum FPCategory {
12241226
/// "Not a Number", often obtained by dividing by zero
1225-
Nan,
1227+
FPNaN,
12261228
/// Positive or negative infinity
1227-
Infinite ,
1229+
FPInfinite ,
12281230
/// Positive or negative zero
1229-
Zero,
1230-
/// De-normalized floating point representation (less precise than `Normal`)
1231-
Subnormal,
1231+
FPZero,
1232+
/// De-normalized floating point representation (less precise than `FPNormal`)
1233+
FPSubnormal,
12321234
/// A regular floating point number
1233-
Normal,
1235+
FPNormal,
12341236
}
12351237

12361238
/// A built-in floating point number.
@@ -1275,7 +1277,7 @@ pub trait Float
12751277
/// Returns true if this number is neither zero, infinite, denormal, or NaN.
12761278
fn is_normal(self) -> bool;
12771279
/// Returns the category that this number falls into.
1278-
fn classify(self) -> FpCategory;
1280+
fn classify(self) -> FPCategory;
12791281

12801282
// FIXME (#5527): These should be associated constants
12811283

branches/snap-stage3/src/libcore/ops.rs

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@
5151
//! See the documentation for each trait for a minimum implementation that prints
5252
//! something to the screen.
5353
54+
use clone::Clone;
55+
use cmp::Ord;
56+
use iter::{Iterator,DoubleEndedIterator};
5457
use kinds::Sized;
58+
use kinds::Copy;
59+
use option::Option::{mod, Some, None};
5560

5661
/// The `Drop` trait is used to run some code when a value goes out of scope. This
5762
/// is sometimes called a 'destructor'.
@@ -833,6 +838,114 @@ pub trait SliceMut<Sized? Idx, Sized? Result> for Sized? {
833838
fn slice_or_fail_mut<'a>(&'a mut self, from: &Idx, to: &Idx) -> &'a mut Result;
834839
}
835840

841+
842+
843+
/// REVIEW could be in a better module
844+
/// The `Countable` trait identifies objects which are countable, i.e., are
845+
/// analogous to the natural numbers. A countable object can be incremented and
846+
/// and decremented and ordered. The `difference` function provides a way to
847+
/// compare two Countable objects (it could be provided using increment and Ord,
848+
/// but the implementation would be so inefficient as to be useless).
849+
#[unstable = "Trait is unstable."]
850+
pub trait Countable: Ord {
851+
// FIXME(#19391) needs a snapshot
852+
//type T;
853+
854+
/// Change self to the next object.
855+
fn increment(&mut self);
856+
/// Change self to the previous object.
857+
fn decrement(&mut self);
858+
/// The difference between two countable objects.
859+
/// Temporarily a uint, should be an associated type, but
860+
// FIXME(#19391) needs a snapshot
861+
fn difference(a: &Self, b: &Self) -> uint;
862+
//fn difference(a: &Self, b: &Self) -> <Self as Countable>::T;
863+
}
864+
865+
macro_rules! countable_impl(
866+
($($t:ty)*) => ($(
867+
#[unstable = "Trait is unstable."]
868+
impl Countable for $t {
869+
// FIXME(#19391) needs a snapshot
870+
//type T = uint;
871+
872+
#[inline]
873+
fn increment(&mut self) { *self += 1; }
874+
#[inline]
875+
fn decrement(&mut self) { *self -= 1; }
876+
#[inline]
877+
fn difference(a: &$t, b: &$t) -> uint { (*a - *b) as uint }
878+
}
879+
)*)
880+
)
881+
882+
countable_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64)
883+
884+
/// An unbounded range.
885+
pub struct FullRange;
886+
887+
/// A range which i bounded at both ends.
888+
pub struct Range<Idx> {
889+
/// The lower bound of the range (inclusive).
890+
pub start: Idx,
891+
/// The upper bound of the range (exclusive).
892+
pub end: Idx,
893+
}
894+
895+
// FIXME(#19391) needs a snapshot
896+
//impl<Idx: Clone + Countable<T=uint>> Iterator<Idx> for Range<Idx> {
897+
impl<Idx: Clone + Countable> Iterator<Idx> for Range<Idx> {
898+
#[inline]
899+
fn next(&mut self) -> Option<Idx> {
900+
if self.start < self.end {
901+
let result = self.start.clone();
902+
self.start.increment();
903+
return Some(result);
904+
}
905+
906+
return None;
907+
}
908+
909+
#[inline]
910+
fn size_hint(&self) -> (uint, Option<uint>) {
911+
let hint = Countable::difference(&self.end, &self.start);
912+
(hint, Some(hint))
913+
}
914+
}
915+
916+
impl<Idx: Clone + Countable> DoubleEndedIterator<Idx> for Range<Idx> {
917+
#[inline]
918+
fn next_back(&mut self) -> Option<Idx> {
919+
if self.start < self.end {
920+
self.end.decrement();
921+
return Some(self.end.clone());
922+
}
923+
924+
return None;
925+
}
926+
}
927+
928+
/// A range which is only bounded below.
929+
pub struct RangeFrom<Idx> {
930+
/// The lower bound of the range (inclusive).
931+
pub start: Idx,
932+
}
933+
934+
impl<Idx: Clone + Countable> Iterator<Idx> for RangeFrom<Idx> {
935+
#[inline]
936+
fn next(&mut self) -> Option<Idx> {
937+
// Deliberately overflow so we loop forever.
938+
let result = self.start.clone();
939+
self.start.increment();
940+
return Some(result);
941+
}
942+
}
943+
944+
impl<Idx: Copy> Copy for Range<Idx> {}
945+
impl<Idx: Copy> Copy for RangeFrom<Idx> {}
946+
impl Copy for FullRange {}
947+
948+
836949
/// The `Deref` trait is used to specify the functionality of dereferencing
837950
/// operations like `*v`.
838951
///

branches/snap-stage3/src/libcoretest/ops.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
use test::Bencher;
12+
use core::ops::{Range, FullRange, RangeFrom};
1213

1314
// Overhead of dtors
1415

@@ -27,3 +28,29 @@ fn alloc_obj_with_dtor(b: &mut Bencher) {
2728
HasDtor { _x : 10 };
2829
})
2930
}
31+
32+
// Test the Range structs without the syntactic sugar.
33+
34+
#[test]
35+
fn test_range() {
36+
let r = Range { start: 2u, end: 10 };
37+
for (i, ri) in r.enumerate() {
38+
assert!(ri == i + 2);
39+
assert!(ri >= 2u && ri < 10u);
40+
}
41+
}
42+
43+
#[test]
44+
fn test_range_from() {
45+
let r = RangeFrom { start: 2u };
46+
for (i, ri) in r.take(10).enumerate() {
47+
assert!(ri == i + 2);
48+
assert!(ri >= 2u && ri < 12u);
49+
}
50+
}
51+
52+
#[test]
53+
fn test_full_range() {
54+
// Not much to test.
55+
let _ = FullRange;
56+
}

branches/snap-stage3/src/librustc/middle/ty.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4212,14 +4212,10 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
42124212
}
42134213

42144214
def::DefStruct(_) => {
4215-
match tcx.node_types.borrow().get(&expr.id) {
4216-
Some(ty) => match ty.sty {
4217-
ty_bare_fn(..) => RvalueDatumExpr,
4218-
_ => RvalueDpsExpr
4219-
},
4220-
// See ExprCast below for why types might be missing.
4221-
None => RvalueDatumExpr
4222-
}
4215+
match expr_ty(tcx, expr).sty {
4216+
ty_bare_fn(..) => RvalueDatumExpr,
4217+
_ => RvalueDpsExpr
4218+
}
42234219
}
42244220

42254221
// Special case: A unit like struct's constructor must be called without () at the

0 commit comments

Comments
 (0)