Skip to content

Commit faca1f4

Browse files
committed
---
yaml --- r: 272813 b: refs/heads/beta c: 3029e09 h: refs/heads/master i: 272811: ee99151
1 parent 188b46c commit faca1f4

File tree

10 files changed

+142
-53
lines changed

10 files changed

+142
-53
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: b3572ae15a8e5d9a8a1cdc1055425a4c3e0cf5f9
26+
refs/heads/beta: 3029e0918de00162932132a7972e566f3a3372f5
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/bootstrap/build/sanity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub fn check(build: &mut Build) {
7979
}
8080

8181
// Make sure musl-root is valid if specified
82-
if target.contains("musl") {
82+
if target.contains("musl") && target.contains("x86_64") {
8383
match build.config.musl_root {
8484
Some(ref root) => {
8585
if fs::metadata(root.join("lib/libc.a")).is_err() {

branches/beta/src/doc/book/vectors.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,36 @@ for i in v {
115115
}
116116
```
117117

118+
Note: You cannot use the vector again once you have iterated by taking ownership of the vector.
119+
You can iterate the vector multiple times by taking a reference to the vector whilst iterating.
120+
For example, the following code does not compile.
121+
122+
```rust,ignore
123+
let mut v = vec![1, 2, 3, 4, 5];
124+
125+
for i in v {
126+
println!("Take ownership of the vector and its element {}", i);
127+
}
128+
129+
for i in v {
130+
println!("Take ownership of the vector and its element {}", i);
131+
}
132+
```
133+
134+
Whereas the following works perfectly,
135+
136+
```rust
137+
let mut v = vec![1, 2, 3, 4, 5];
138+
139+
for i in &v {
140+
println!("This is a reference to {}", i);
141+
}
142+
143+
for i in &v {
144+
println!("This is a reference to {}", i);
145+
}
146+
```
147+
118148
Vectors have many more useful methods, which you can read about in [their
119149
API documentation][vec].
120150

branches/beta/src/libcore/iter.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,7 @@ pub trait Iterator {
15321532
/// An iterator adaptor that applies a function, producing a single, final value.
15331533
///
15341534
/// `fold()` takes two arguments: an initial value, and a closure with two
1535-
/// arguments: an 'accumulator', and an element. It returns the value that
1535+
/// arguments: an 'accumulator', and an element. The closure returns the value that
15361536
/// the accumulator should have for the next iteration.
15371537
///
15381538
/// The initial value is the value the accumulator will have on the first
@@ -3851,6 +3851,17 @@ impl<I> Iterator for Skip<I> where I: Iterator {
38513851
#[stable(feature = "rust1", since = "1.0.0")]
38523852
impl<I> ExactSizeIterator for Skip<I> where I: ExactSizeIterator {}
38533853

3854+
#[stable(feature = "double_ended_skip_iterator", since = "1.8.0")]
3855+
impl<I> DoubleEndedIterator for Skip<I> where I: DoubleEndedIterator + ExactSizeIterator {
3856+
fn next_back(&mut self) -> Option<Self::Item> {
3857+
if self.len() > 0 {
3858+
self.iter.next_back()
3859+
} else {
3860+
None
3861+
}
3862+
}
3863+
}
3864+
38543865
/// An iterator that only iterates over the first `n` iterations of `iter`.
38553866
///
38563867
/// This `struct` is created by the [`take()`] method on [`Iterator`]. See its

branches/beta/src/libcore/str/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,8 +1095,6 @@ fn eq_slice(a: &str, b: &str) -> bool {
10951095
/// faster than comparing each byte in a loop.
10961096
#[inline]
10971097
unsafe fn cmp_slice(a: &str, b: &str, len: usize) -> i32 {
1098-
// NOTE: In theory n should be libc::size_t and not usize, but libc is not available here
1099-
#[allow(improper_ctypes)]
11001098
extern { fn memcmp(s1: *const i8, s2: *const i8, n: usize) -> i32; }
11011099
memcmp(a.as_ptr() as *const i8, b.as_ptr() as *const i8, len)
11021100
}

branches/beta/src/libcoretest/iter.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,44 @@ fn test_iterator_skip() {
303303
assert_eq!(it.len(), 0);
304304
}
305305

306+
#[test]
307+
fn test_iterator_skip_doubleended() {
308+
let xs = [0, 1, 2, 3, 5, 13, 15, 16, 17, 19, 20, 30];
309+
let mut it = xs.iter().rev().skip(5);
310+
assert_eq!(it.next(), Some(&15));
311+
assert_eq!(it.by_ref().rev().next(), Some(&0));
312+
assert_eq!(it.next(), Some(&13));
313+
assert_eq!(it.by_ref().rev().next(), Some(&1));
314+
assert_eq!(it.next(), Some(&5));
315+
assert_eq!(it.by_ref().rev().next(), Some(&2));
316+
assert_eq!(it.next(), Some(&3));
317+
assert_eq!(it.next(), None);
318+
let mut it = xs.iter().rev().skip(5).rev();
319+
assert_eq!(it.next(), Some(&0));
320+
assert_eq!(it.rev().next(), Some(&15));
321+
let mut it_base = xs.iter();
322+
{
323+
let mut it = it_base.by_ref().skip(5).rev();
324+
assert_eq!(it.next(), Some(&30));
325+
assert_eq!(it.next(), Some(&20));
326+
assert_eq!(it.next(), Some(&19));
327+
assert_eq!(it.next(), Some(&17));
328+
assert_eq!(it.next(), Some(&16));
329+
assert_eq!(it.next(), Some(&15));
330+
assert_eq!(it.next(), Some(&13));
331+
assert_eq!(it.next(), None);
332+
}
333+
// make sure the skipped parts have not been consumed
334+
assert_eq!(it_base.next(), Some(&0));
335+
assert_eq!(it_base.next(), Some(&1));
336+
assert_eq!(it_base.next(), Some(&2));
337+
assert_eq!(it_base.next(), Some(&3));
338+
assert_eq!(it_base.next(), Some(&5));
339+
assert_eq!(it_base.next(), None);
340+
let it = xs.iter().skip(5).rev();
341+
assert_eq!(it.last(), Some(&13));
342+
}
343+
306344
#[test]
307345
fn test_iterator_skip_nth() {
308346
let xs = [0, 1, 2, 3, 5, 13, 15, 16, 17, 19, 20, 30];

branches/beta/src/librustc_typeck/check/_match.rs

Lines changed: 29 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
203203
check_pat_enum(pcx, pat, path, subpats.as_ref().map(|v| &v[..]), expected, true);
204204
}
205205
PatKind::Path(ref path) => {
206-
check_pat_enum(pcx, pat, path, None, expected, false);
206+
check_pat_enum(pcx, pat, path, Some(&[]), expected, false);
207207
}
208208
PatKind::QPath(ref qself, ref path) => {
209209
let self_ty = fcx.to_ty(&qself.ty);
@@ -597,12 +597,12 @@ fn bad_struct_kind_err(sess: &Session, pat: &hir::Pat, path: &hir::Path, lint: b
597597
}
598598
}
599599

600-
pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
601-
pat: &hir::Pat,
602-
path: &hir::Path,
603-
subpats: Option<&'tcx [P<hir::Pat>]>,
604-
expected: Ty<'tcx>,
605-
is_tuple_struct_pat: bool)
600+
fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
601+
pat: &hir::Pat,
602+
path: &hir::Path,
603+
subpats: Option<&'tcx [P<hir::Pat>]>,
604+
expected: Ty<'tcx>,
605+
is_tuple_struct_pat: bool)
606606
{
607607
// Typecheck the path.
608608
let fcx = pcx.fcx;
@@ -685,59 +685,41 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
685685
demand::eqtype(fcx, pat.span, expected, pat_ty);
686686

687687
let real_path_ty = fcx.node_ty(pat.id);
688-
let (arg_tys, kind_name): (Vec<_>, &'static str) = match real_path_ty.sty {
688+
let (kind_name, variant, expected_substs) = match real_path_ty.sty {
689689
ty::TyEnum(enum_def, expected_substs) => {
690690
let variant = enum_def.variant_of_def(def);
691-
if variant.kind() == ty::VariantKind::Struct {
692-
report_bad_struct_kind(false);
693-
return;
694-
}
695-
if is_tuple_struct_pat && variant.kind() != ty::VariantKind::Tuple {
696-
// Matching unit variants with tuple variant patterns (`UnitVariant(..)`)
697-
// is allowed for backward compatibility.
698-
let is_special_case = variant.kind() == ty::VariantKind::Unit;
699-
report_bad_struct_kind(is_special_case);
700-
if !is_special_case {
701-
return
702-
}
703-
}
704-
(variant.fields
705-
.iter()
706-
.map(|f| fcx.instantiate_type_scheme(pat.span,
707-
expected_substs,
708-
&f.unsubst_ty()))
709-
.collect(),
710-
"variant")
691+
("variant", variant, expected_substs)
711692
}
712693
ty::TyStruct(struct_def, expected_substs) => {
713694
let variant = struct_def.struct_variant();
714-
if is_tuple_struct_pat && variant.kind() != ty::VariantKind::Tuple {
715-
// Matching unit structs with tuple variant patterns (`UnitVariant(..)`)
716-
// is allowed for backward compatibility.
717-
let is_special_case = variant.kind() == ty::VariantKind::Unit;
718-
report_bad_struct_kind(is_special_case);
719-
return;
720-
}
721-
(variant.fields
722-
.iter()
723-
.map(|f| fcx.instantiate_type_scheme(pat.span,
724-
expected_substs,
725-
&f.unsubst_ty()))
726-
.collect(),
727-
"struct")
695+
("struct", variant, expected_substs)
728696
}
729697
_ => {
730698
report_bad_struct_kind(false);
731699
return;
732700
}
733701
};
734702

703+
match (is_tuple_struct_pat, variant.kind()) {
704+
(true, ty::VariantKind::Unit) => {
705+
// Matching unit structs with tuple variant patterns (`UnitVariant(..)`)
706+
// is allowed for backward compatibility.
707+
report_bad_struct_kind(true);
708+
}
709+
(_, ty::VariantKind::Struct) => {
710+
report_bad_struct_kind(false);
711+
return
712+
}
713+
_ => {}
714+
}
715+
735716
if let Some(subpats) = subpats {
736-
if subpats.len() == arg_tys.len() {
737-
for (subpat, arg_ty) in subpats.iter().zip(arg_tys) {
738-
check_pat(pcx, &subpat, arg_ty);
717+
if subpats.len() == variant.fields.len() {
718+
for (subpat, field) in subpats.iter().zip(&variant.fields) {
719+
let field_ty = fcx.field_ty(subpat.span, field, expected_substs);
720+
check_pat(pcx, &subpat, field_ty);
739721
}
740-
} else if arg_tys.is_empty() {
722+
} else if variant.fields.is_empty() {
741723
span_err!(tcx.sess, pat.span, E0024,
742724
"this pattern has {} field{}, but the corresponding {} has no fields",
743725
subpats.len(), if subpats.len() == 1 {""} else {"s"}, kind_name);
@@ -750,7 +732,7 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
750732
"this pattern has {} field{}, but the corresponding {} has {} field{}",
751733
subpats.len(), if subpats.len() == 1 {""} else {"s"},
752734
kind_name,
753-
arg_tys.len(), if arg_tys.len() == 1 {""} else {"s"});
735+
variant.fields.len(), if variant.fields.len() == 1 {""} else {"s"});
754736

755737
for pat in subpats {
756738
check_pat(pcx, &pat, tcx.types.err);

branches/beta/src/libstd/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn main() {
2828
}
2929

3030
if target.contains("unknown-linux") {
31-
if target.contains("musl") {
31+
if target.contains("musl") && target.contains("x86_64") {
3232
println!("cargo:rustc-link-lib=static=unwind");
3333
} else {
3434
println!("cargo:rustc-link-lib=dl");
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum Foo {
12+
Bar(i32),
13+
Baz
14+
}
15+
16+
struct S;
17+
18+
fn main() {
19+
match Foo::Baz {
20+
Foo::Bar => {}
21+
//~^ ERROR this pattern has 0 fields, but the corresponding variant
22+
_ => {}
23+
}
24+
25+
match S {
26+
S(()) => {}
27+
//~^ ERROR this pattern has 1 field, but the corresponding struct
28+
}
29+
}

branches/beta/src/test/rustdoc/issue-27362.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
// aux-build:issue-27362.rs
1212
// ignore-cross-compile
13+
// ignore-test This test fails on beta/stable #32019
1314

1415
extern crate issue_27362;
1516
pub use issue_27362 as quux;

0 commit comments

Comments
 (0)