From 9bf73d24d0fdc4f6dbca702ec85c5583abc921cd Mon Sep 17 00:00:00 2001 From: srinivasreddy Date: Wed, 2 Mar 2016 09:36:30 +0530 Subject: [PATCH 1/8] Explained the difference between ownership iteration and reference iteration --- src/doc/book/vectors.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/doc/book/vectors.md b/src/doc/book/vectors.md index f5a543d75b1b4..0eba4d40ede01 100644 --- a/src/doc/book/vectors.md +++ b/src/doc/book/vectors.md @@ -114,7 +114,30 @@ for i in v { println!("Take ownership of the vector and its element {}", i); } ``` +Note: You cannot use the vector again once you have iterated with ownership of the vector. +You can iterate the vector multiple times with reference iteration. For example, the following +code does not compile. +```rust +let mut v = vec![1, 2, 3, 4, 5]; +for i in v { + println!("Take ownership of the vector and its element {}", i); +} +for i in v { + println!("Take ownership of the vector and its element {}", i); +} +``` +Whereas the following works perfectly, +```rust +let mut v = vec![1, 2, 3, 4, 5]; +for i in &v { + println!("A mutable reference to {}", i); +} + +for i in &v { + println!("A mutable reference to {}", i); +} +``` Vectors have many more useful methods, which you can read about in [their API documentation][vec]. From a3c9afa841aba127edac2bb60e2f2a720a51d8ac Mon Sep 17 00:00:00 2001 From: srinivasreddy Date: Wed, 2 Mar 2016 20:31:26 +0530 Subject: [PATCH 2/8] addressed review comments - grammar corrections, space additions --- src/doc/book/vectors.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/doc/book/vectors.md b/src/doc/book/vectors.md index 0eba4d40ede01..d9379117c86b8 100644 --- a/src/doc/book/vectors.md +++ b/src/doc/book/vectors.md @@ -114,30 +114,37 @@ for i in v { println!("Take ownership of the vector and its element {}", i); } ``` -Note: You cannot use the vector again once you have iterated with ownership of the vector. -You can iterate the vector multiple times with reference iteration. For example, the following -code does not compile. + +Note: You cannot use the vector again once you have iterated by taking ownership of the vector. +You can iterate the vector multiple times by taking a reference to the vector whilst iterating. +For example, the following code does not compile. + ```rust let mut v = vec![1, 2, 3, 4, 5]; + for i in v { println!("Take ownership of the vector and its element {}", i); } + for i in v { println!("Take ownership of the vector and its element {}", i); } ``` + Whereas the following works perfectly, ```rust let mut v = vec![1, 2, 3, 4, 5]; + for i in &v { - println!("A mutable reference to {}", i); + println!("This is a reference to {}", i); } for i in &v { - println!("A mutable reference to {}", i); + println!("This is a reference {}", i); } ``` + Vectors have many more useful methods, which you can read about in [their API documentation][vec]. From 2dc723de9a1f842fad084791cbe6029b710cf93b Mon Sep 17 00:00:00 2001 From: srinivasreddy Date: Wed, 2 Mar 2016 20:42:26 +0530 Subject: [PATCH 3/8] made print message similar across two loops --- src/doc/book/vectors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/book/vectors.md b/src/doc/book/vectors.md index d9379117c86b8..1c120186aabbd 100644 --- a/src/doc/book/vectors.md +++ b/src/doc/book/vectors.md @@ -141,7 +141,7 @@ for i in &v { } for i in &v { - println!("This is a reference {}", i); + println!("This is a reference to {}", i); } ``` From d3ae29d9c101a4495d95faa6e2266a04630765f1 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 3 Mar 2016 00:34:18 +0000 Subject: [PATCH 4/8] Ignore a rustdoc test that does not work on beta --- src/test/rustdoc/issue-27362.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/rustdoc/issue-27362.rs b/src/test/rustdoc/issue-27362.rs index 179778fd1283f..b28fb7ec47a8c 100644 --- a/src/test/rustdoc/issue-27362.rs +++ b/src/test/rustdoc/issue-27362.rs @@ -10,6 +10,7 @@ // aux-build:issue-27362.rs // ignore-cross-compile +// ignore-test This test fails on beta/stable #32019 extern crate issue_27362; pub use issue_27362 as quux; From d2df5514c09aa0d9a648183b33b5b1ee1c6d0fa2 Mon Sep 17 00:00:00 2001 From: srinivasreddy Date: Thu, 3 Mar 2016 21:54:21 +0530 Subject: [PATCH 5/8] added ignore --- src/doc/book/vectors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/book/vectors.md b/src/doc/book/vectors.md index 1c120186aabbd..ceb6b3c003e52 100644 --- a/src/doc/book/vectors.md +++ b/src/doc/book/vectors.md @@ -119,7 +119,7 @@ Note: You cannot use the vector again once you have iterated by taking ownership You can iterate the vector multiple times by taking a reference to the vector whilst iterating. For example, the following code does not compile. -```rust +```rust,ignore let mut v = vec![1, 2, 3, 4, 5]; for i in v { From ddd2e99d0235b968fffab9e6ae94c660a1fb85de Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 3 Mar 2016 14:50:28 -0500 Subject: [PATCH 6/8] [rustbuild] fix cross compilation of std for mips(el)-linux-musl These targets don't link statically to libunwind or libc --- src/bootstrap/build/sanity.rs | 2 +- src/libstd/build.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/build/sanity.rs b/src/bootstrap/build/sanity.rs index 40f4c7076092d..6ac581a7c6949 100644 --- a/src/bootstrap/build/sanity.rs +++ b/src/bootstrap/build/sanity.rs @@ -79,7 +79,7 @@ pub fn check(build: &mut Build) { } // Make sure musl-root is valid if specified - if target.contains("musl") { + if target.contains("musl") && target.contains("x86_64") { match build.config.musl_root { Some(ref root) => { if fs::metadata(root.join("lib/libc.a")).is_err() { diff --git a/src/libstd/build.rs b/src/libstd/build.rs index a1144a964fd37..c60ec4d3655b0 100644 --- a/src/libstd/build.rs +++ b/src/libstd/build.rs @@ -28,7 +28,7 @@ fn main() { } if target.contains("unknown-linux") { - if target.contains("musl") { + if target.contains("musl") && target.contains("x86_64") { println!("cargo:rustc-link-lib=static=unwind"); } else { println!("cargo:rustc-link-lib=dl"); From 633cd84821431e93a3e40f662cbe00ba21755811 Mon Sep 17 00:00:00 2001 From: ubsan Date: Thu, 3 Mar 2016 19:53:31 -0800 Subject: [PATCH 7/8] `usize` is now a proper ctype, so fix cmp_slice --- src/libcore/str/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 4d367cfd432f9..14f189409be63 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -1095,8 +1095,6 @@ fn eq_slice(a: &str, b: &str) -> bool { /// faster than comparing each byte in a loop. #[inline] unsafe fn cmp_slice(a: &str, b: &str, len: usize) -> i32 { - // NOTE: In theory n should be libc::size_t and not usize, but libc is not available here - #[allow(improper_ctypes)] extern { fn memcmp(s1: *const i8, s2: *const i8, n: usize) -> i32; } memcmp(a.as_ptr() as *const i8, b.as_ptr() as *const i8, len) } From 84e6e04d83d02e09e8b659267e415ec8b5bc2a24 Mon Sep 17 00:00:00 2001 From: Brian Bowman Date: Fri, 4 Mar 2016 01:09:23 -0600 Subject: [PATCH 8/8] Clarify ambiguous wording in fold() docs To me it was unclear whether 'it' referred to the fold function, or the closure. --- src/libcore/iter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index d6bd9dbf4bde2..a730b9bd518da 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -1532,7 +1532,7 @@ pub trait Iterator { /// An iterator adaptor that applies a function, producing a single, final value. /// /// `fold()` takes two arguments: an initial value, and a closure with two - /// arguments: an 'accumulator', and an element. It returns the value that + /// arguments: an 'accumulator', and an element. The closure returns the value that /// the accumulator should have for the next iteration. /// /// The initial value is the value the accumulator will have on the first