Skip to content

Commit 3462380

Browse files
committed
---
yaml --- r: 232791 b: refs/heads/try c: 1c7c6ad h: refs/heads/master i: 232789: 9ba6d0b 232787: e9d11bb 232783: fc568e9 v: v3
1 parent f54a9c1 commit 3462380

File tree

33 files changed

+461
-192
lines changed

33 files changed

+461
-192
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: edeb4f1c86cbf6af8ef9874d4b3af50f721ea1b8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: 21f209a28b7294fb7afe73cc5a37aad93d426b75
4+
refs/heads/try: 1c7c6adf5f3bdcf7f95e1bf1eec2c85ce96b5c92
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/doc/trpl/testing.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,26 @@ And that's reflected in the summary line:
120120
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured
121121
```
122122

123-
We also get a non-zero status code:
123+
We also get a non-zero status code. We can use `$?` on OS X and Linux:
124124

125125
```bash
126126
$ echo $?
127127
101
128128
```
129129

130+
On Windows, if you’re using `cmd`:
131+
132+
```bash
133+
> echo %ERRORLEVEL%
134+
```
135+
136+
And if you’re using PowerShell:
137+
138+
```bash
139+
> echo $LASTEXITCODE # the code itself
140+
> echo $? # a boolean, fail or succeed
141+
```
142+
130143
This is useful if you want to integrate `cargo test` into other tooling.
131144

132145
We can invert our test's failure with another attribute: `should_panic`:

branches/try/src/libcore/marker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub trait Sized {
4545
}
4646

4747
/// Types that can be "unsized" to a dynamically sized type.
48-
#[unstable(feature = "unsize", issue = "27779")]
48+
#[unstable(feature = "unsize", issue = "27732")]
4949
#[lang="unsize"]
5050
pub trait Unsize<T: ?Sized> {
5151
// Empty.

branches/try/src/libcore/ops.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ pub trait Rem<RHS=Self> {
423423
fn rem(self, rhs: RHS) -> Self::Output;
424424
}
425425

426-
macro_rules! rem_impl {
426+
macro_rules! rem_impl_integer {
427427
($($t:ty)*) => ($(
428428
/// This operation satisfies `n % d == n - (n / d) * d`. The
429429
/// result has the same sign as the left operand.
@@ -439,9 +439,28 @@ macro_rules! rem_impl {
439439
)*)
440440
}
441441

442-
rem_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
442+
rem_impl_integer! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
443+
444+
#[cfg(not(stage0))]
445+
macro_rules! rem_impl_float {
446+
($($t:ty)*) => ($(
447+
#[stable(feature = "rust1", since = "1.0.0")]
448+
impl Rem for $t {
449+
type Output = $t;
450+
451+
#[inline]
452+
fn rem(self, other: $t) -> $t { self % other }
453+
}
454+
455+
forward_ref_binop! { impl Rem, rem for $t, $t }
456+
)*)
457+
}
458+
459+
#[cfg(not(stage0))]
460+
rem_impl_float! { f32 f64 }
443461

444462
#[stable(feature = "rust1", since = "1.0.0")]
463+
#[cfg(stage0)]
445464
impl Rem for f32 {
446465
type Output = f32;
447466

@@ -463,6 +482,7 @@ impl Rem for f32 {
463482
}
464483

465484
#[stable(feature = "rust1", since = "1.0.0")]
485+
#[cfg(stage0)]
466486
impl Rem for f64 {
467487
type Output = f64;
468488

@@ -473,7 +493,9 @@ impl Rem for f64 {
473493
}
474494
}
475495

496+
#[cfg(stage0)]
476497
forward_ref_binop! { impl Rem, rem for f64, f64 }
498+
#[cfg(stage0)]
477499
forward_ref_binop! { impl Rem, rem for f32, f32 }
478500

479501
/// The `Neg` trait is used to specify the functionality of unary `-`.

branches/try/src/libcore/option.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,26 @@ impl<T> IntoIterator for Option<T> {
779779
}
780780
}
781781

782+
#[stable(since = "1.4.0", feature = "option_iter")]
783+
impl<'a, T> IntoIterator for &'a Option<T> {
784+
type Item = &'a T;
785+
type IntoIter = Iter<'a, T>;
786+
787+
fn into_iter(self) -> Iter<'a, T> {
788+
self.iter()
789+
}
790+
}
791+
792+
#[stable(since = "1.4.0", feature = "option_iter")]
793+
impl<'a, T> IntoIterator for &'a mut Option<T> {
794+
type Item = &'a mut T;
795+
type IntoIter = IterMut<'a, T>;
796+
797+
fn into_iter(mut self) -> IterMut<'a, T> {
798+
self.iter_mut()
799+
}
800+
}
801+
782802
/////////////////////////////////////////////////////////////////////////////
783803
// The Option Iterators
784804
/////////////////////////////////////////////////////////////////////////////

branches/try/src/libcore/result.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,26 @@ impl<T, E> IntoIterator for Result<T, E> {
815815
}
816816
}
817817

818+
#[stable(since = "1.4.0", feature = "result_iter")]
819+
impl<'a, T, E> IntoIterator for &'a Result<T, E> {
820+
type Item = &'a T;
821+
type IntoIter = Iter<'a, T>;
822+
823+
fn into_iter(self) -> Iter<'a, T> {
824+
self.iter()
825+
}
826+
}
827+
828+
#[stable(since = "1.4.0", feature = "result_iter")]
829+
impl<'a, T, E> IntoIterator for &'a mut Result<T, E> {
830+
type Item = &'a mut T;
831+
type IntoIter = IterMut<'a, T>;
832+
833+
fn into_iter(mut self) -> IterMut<'a, T> {
834+
self.iter_mut()
835+
}
836+
}
837+
818838
/////////////////////////////////////////////////////////////////////////////
819839
// The Result Iterators
820840
/////////////////////////////////////////////////////////////////////////////

branches/try/src/libcoretest/option.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,14 @@ fn test_iter() {
180180
assert_eq!(it.next(), Some(&val));
181181
assert_eq!(it.size_hint(), (0, Some(0)));
182182
assert!(it.next().is_none());
183+
184+
let mut it = (&x).into_iter();
185+
assert_eq!(it.next(), Some(&val));
183186
}
184187

185188
#[test]
186189
fn test_mut_iter() {
187-
let val = 5;
190+
let mut val = 5;
188191
let new_val = 11;
189192

190193
let mut x = Some(val);
@@ -205,6 +208,10 @@ fn test_mut_iter() {
205208
assert!(it.next().is_none());
206209
}
207210
assert_eq!(x, Some(new_val));
211+
212+
let mut y = Some(val);
213+
let mut it = (&mut y).into_iter();
214+
assert_eq!(it.next(), Some(&mut val));
208215
}
209216

210217
#[test]

branches/try/src/libcoretest/result.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,36 @@ pub fn test_expect_err() {
150150
let err: Result<isize, &'static str> = Err("All good");
151151
err.expect("Got expected error");
152152
}
153+
154+
#[test]
155+
pub fn test_iter() {
156+
let ok: Result<isize, &'static str> = Ok(100);
157+
let mut it = ok.iter();
158+
assert_eq!(it.size_hint(), (1, Some(1)));
159+
assert_eq!(it.next(), Some(&100));
160+
assert_eq!(it.size_hint(), (0, Some(0)));
161+
assert!(it.next().is_none());
162+
assert_eq!((&ok).into_iter().next(), Some(&100));
163+
164+
let err: Result<isize, &'static str> = Err("error");
165+
assert_eq!(err.iter().next(), None);
166+
}
167+
168+
#[test]
169+
pub fn test_iter_mut() {
170+
let mut ok: Result<isize, &'static str> = Ok(100);
171+
for loc in ok.iter_mut() {
172+
*loc = 200;
173+
}
174+
assert_eq!(ok, Ok(200));
175+
for loc in &mut ok {
176+
*loc = 300;
177+
}
178+
assert_eq!(ok, Ok(300));
179+
180+
let mut err: Result<isize, &'static str> = Err("error");
181+
for loc in err.iter_mut() {
182+
*loc = 200;
183+
}
184+
assert_eq!(err, Err("error"));
185+
}

branches/try/src/librustc_trans/trans/_match.rs

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -875,19 +875,17 @@ fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
875875
debug_loc: DebugLoc)
876876
-> Result<'blk, 'tcx> {
877877
fn compare_str<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
878-
lhs: ValueRef,
879-
rhs: ValueRef,
878+
lhs_data: ValueRef,
879+
lhs_len: ValueRef,
880+
rhs_data: ValueRef,
881+
rhs_len: ValueRef,
880882
rhs_t: Ty<'tcx>,
881883
debug_loc: DebugLoc)
882884
-> Result<'blk, 'tcx> {
883885
let did = langcall(cx,
884886
None,
885887
&format!("comparison of `{}`", rhs_t),
886888
StrEqFnLangItem);
887-
let lhs_data = Load(cx, expr::get_dataptr(cx, lhs));
888-
let lhs_len = Load(cx, expr::get_meta(cx, lhs));
889-
let rhs_data = Load(cx, expr::get_dataptr(cx, rhs));
890-
let rhs_len = Load(cx, expr::get_meta(cx, rhs));
891889
callee::trans_lang_call(cx, did, &[lhs_data, lhs_len, rhs_data, rhs_len], None, debug_loc)
892890
}
893891

@@ -899,32 +897,38 @@ fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
899897

900898
match rhs_t.sty {
901899
ty::TyRef(_, mt) => match mt.ty.sty {
902-
ty::TyStr => compare_str(cx, lhs, rhs, rhs_t, debug_loc),
900+
ty::TyStr => {
901+
let lhs_data = Load(cx, expr::get_dataptr(cx, lhs));
902+
let lhs_len = Load(cx, expr::get_meta(cx, lhs));
903+
let rhs_data = Load(cx, expr::get_dataptr(cx, rhs));
904+
let rhs_len = Load(cx, expr::get_meta(cx, rhs));
905+
compare_str(cx, lhs_data, lhs_len, rhs_data, rhs_len, rhs_t, debug_loc)
906+
}
903907
ty::TyArray(ty, _) | ty::TySlice(ty) => match ty.sty {
904908
ty::TyUint(ast::TyU8) => {
905909
// NOTE: cast &[u8] and &[u8; N] to &str and abuse the str_eq lang item,
906910
// which calls memcmp().
907911
let pat_len = val_ty(rhs).element_type().array_length();
908912
let ty_str_slice = cx.tcx().mk_static_str();
909913

910-
let rhs_str = alloc_ty(cx, ty_str_slice, "rhs_str");
911-
Store(cx, expr::get_dataptr(cx, rhs), expr::get_dataptr(cx, rhs_str));
912-
Store(cx, C_uint(cx.ccx(), pat_len), expr::get_meta(cx, rhs_str));
914+
let rhs_data = GEPi(cx, rhs, &[0, 0]);
915+
let rhs_len = C_uint(cx.ccx(), pat_len);
913916

914-
let lhs_str;
917+
let lhs_data;
918+
let lhs_len;
915919
if val_ty(lhs) == val_ty(rhs) {
916920
// Both the discriminant and the pattern are thin pointers
917-
lhs_str = alloc_ty(cx, ty_str_slice, "lhs_str");
918-
Store(cx, expr::get_dataptr(cx, lhs), expr::get_dataptr(cx, lhs_str));
919-
Store(cx, C_uint(cx.ccx(), pat_len), expr::get_meta(cx, lhs_str));
920-
}
921-
else {
921+
lhs_data = GEPi(cx, lhs, &[0, 0]);
922+
lhs_len = C_uint(cx.ccx(), pat_len);
923+
} else {
922924
// The discriminant is a fat pointer
923925
let llty_str_slice = type_of::type_of(cx.ccx(), ty_str_slice).ptr_to();
924-
lhs_str = PointerCast(cx, lhs, llty_str_slice);
926+
let lhs_str = PointerCast(cx, lhs, llty_str_slice);
927+
lhs_data = Load(cx, expr::get_dataptr(cx, lhs_str));
928+
lhs_len = Load(cx, expr::get_meta(cx, lhs_str));
925929
}
926930

927-
compare_str(cx, lhs_str, rhs_str, rhs_t, debug_loc)
931+
compare_str(cx, lhs_data, lhs_len, rhs_data, rhs_len, rhs_t, debug_loc)
928932
},
929933
_ => cx.sess().bug("only byte strings supported in compare_values"),
930934
},
@@ -1192,8 +1196,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
11921196
let unsized_ty = def.struct_variant().fields.last().map(|field| {
11931197
monomorphize::field_ty(bcx.tcx(), substs, field)
11941198
}).unwrap();
1195-
let llty = type_of::type_of(bcx.ccx(), unsized_ty);
1196-
let scratch = alloca_no_lifetime(bcx, llty, "__struct_field_fat_ptr");
1199+
let scratch = alloc_ty(bcx, unsized_ty, "__struct_field_fat_ptr");
11971200
let data = adt::trans_field_ptr(bcx, &*repr, struct_val, 0, arg_count);
11981201
let len = Load(bcx, expr::get_meta(bcx, val.val));
11991202
Store(bcx, data, expr::get_dataptr(bcx, scratch));
@@ -1520,12 +1523,8 @@ fn create_bindings_map<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, pat: &ast::Pat,
15201523
match bm {
15211524
ast::BindByValue(_) if !moves_by_default || reassigned =>
15221525
{
1523-
llmatch = alloca_no_lifetime(bcx,
1524-
llvariable_ty.ptr_to(),
1525-
"__llmatch");
1526-
let llcopy = alloca_no_lifetime(bcx,
1527-
llvariable_ty,
1528-
&bcx.name(name));
1526+
llmatch = alloca(bcx, llvariable_ty.ptr_to(), "__llmatch");
1527+
let llcopy = alloca(bcx, llvariable_ty, &bcx.name(name));
15291528
trmode = if moves_by_default {
15301529
TrByMoveIntoCopy(llcopy)
15311530
} else {
@@ -1536,15 +1535,11 @@ fn create_bindings_map<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, pat: &ast::Pat,
15361535
// in this case, the final type of the variable will be T,
15371536
// but during matching we need to store a *T as explained
15381537
// above
1539-
llmatch = alloca_no_lifetime(bcx,
1540-
llvariable_ty.ptr_to(),
1541-
&bcx.name(name));
1538+
llmatch = alloca(bcx, llvariable_ty.ptr_to(), &bcx.name(name));
15421539
trmode = TrByMoveRef;
15431540
}
15441541
ast::BindByRef(_) => {
1545-
llmatch = alloca_no_lifetime(bcx,
1546-
llvariable_ty,
1547-
&bcx.name(name));
1542+
llmatch = alloca(bcx, llvariable_ty, &bcx.name(name));
15481543
trmode = TrByRef;
15491544
}
15501545
};
@@ -1745,6 +1740,7 @@ fn mk_binding_alloca<'blk, 'tcx, A, F>(bcx: Block<'blk, 'tcx>,
17451740

17461741
// Subtle: be sure that we *populate* the memory *before*
17471742
// we schedule the cleanup.
1743+
call_lifetime_start(bcx, llval);
17481744
let bcx = populate(arg, bcx, datum);
17491745
bcx.fcx.schedule_lifetime_end(cleanup_scope, llval);
17501746
bcx.fcx.schedule_drop_mem(cleanup_scope, llval, var_ty, lvalue.dropflag_hint(bcx));

branches/try/src/librustc_trans/trans/base.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,17 +1020,10 @@ pub fn alloc_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: Ty<'tcx>, name: &str) ->
10201020
let ccx = bcx.ccx();
10211021
let ty = type_of::type_of(ccx, t);
10221022
assert!(!t.has_param_types());
1023-
let val = alloca(bcx, ty, name);
1024-
return val;
1023+
alloca(bcx, ty, name)
10251024
}
10261025

10271026
pub fn alloca(cx: Block, ty: Type, name: &str) -> ValueRef {
1028-
let p = alloca_no_lifetime(cx, ty, name);
1029-
call_lifetime_start(cx, p);
1030-
p
1031-
}
1032-
1033-
pub fn alloca_no_lifetime(cx: Block, ty: Type, name: &str) -> ValueRef {
10341027
let _icx = push_ctxt("alloca");
10351028
if cx.unreachable.get() {
10361029
unsafe {
@@ -1742,7 +1735,9 @@ pub fn trans_named_tuple_constructor<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
17421735
expr::SaveIn(d) => d,
17431736
expr::Ignore => {
17441737
if !type_is_zero_size(ccx, result_ty) {
1745-
alloc_ty(bcx, result_ty, "constructor_result")
1738+
let llresult = alloc_ty(bcx, result_ty, "constructor_result");
1739+
call_lifetime_start(bcx, llresult);
1740+
llresult
17461741
} else {
17471742
C_undef(type_of::type_of(ccx, result_ty).ptr_to())
17481743
}

branches/try/src/librustc_trans/trans/callee.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,9 @@ pub fn trans_call_inner<'a, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
725725
let llty = type_of::type_of(ccx, ret_ty);
726726
Some(common::C_undef(llty.ptr_to()))
727727
} else {
728-
Some(alloc_ty(bcx, ret_ty, "__llret"))
728+
let llresult = alloc_ty(bcx, ret_ty, "__llret");
729+
call_lifetime_start(bcx, llresult);
730+
Some(llresult)
729731
}
730732
} else {
731733
None

0 commit comments

Comments
 (0)