From 6e2f18ef322c094ed49eee11994fc49c5cacbc2a Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Sun, 31 May 2015 14:03:57 +0200 Subject: [PATCH 01/10] Add loopcounter section to the for-loop chapter Sometimes loop counters are useful and we should show new users how it is achieved in Rust. --- src/doc/trpl/for-loops.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/doc/trpl/for-loops.md b/src/doc/trpl/for-loops.md index 1e3f2fa54bcc6..c8422f351d13b 100644 --- a/src/doc/trpl/for-loops.md +++ b/src/doc/trpl/for-loops.md @@ -41,3 +41,38 @@ so our loop will print `0` through `9`, not `10`. Rust does not have the “C-style” `for` loop on purpose. Manually controlling each element of the loop is complicated and error prone, even for experienced C developers. + +# Loopcounter + +When you need to keep track of how many times you already looped, you can use the `.enumerate()` function. + +#### On ranges: + +```rust +for (i,j) in (5..10).enumerate() { + println!("i = {} and j = {}", i, j); +} +``` +Outputs: +``` +i = 0 and j = 5 +i = 1 and j = 6 +i = 2 and j = 7 +i = 3 and j = 8 +i = 4 and j = 9 +``` +Don't forget to add the parentheses around the range. + +#### On iterators: +```rust +for (linenumber, line) in lines.enumerate() { + println!("{}: {}", linenumber, line); +} +``` +Outputs: +``` +0: Content of line one +1: Content of line two +2: Content of line tree +3: Content of line four +``` From 151c3d3644c2d8b21465dd8a48ad753539e18c88 Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Sun, 31 May 2015 20:56:35 +0200 Subject: [PATCH 02/10] Corrected some formatting issues --- src/doc/trpl/for-loops.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/doc/trpl/for-loops.md b/src/doc/trpl/for-loops.md index c8422f351d13b..9cd1689cf3dea 100644 --- a/src/doc/trpl/for-loops.md +++ b/src/doc/trpl/for-loops.md @@ -42,35 +42,41 @@ Rust does not have the “C-style” `for` loop on purpose. Manually controlling each element of the loop is complicated and error prone, even for experienced C developers. -# Loopcounter +# Enumerate When you need to keep track of how many times you already looped, you can use the `.enumerate()` function. -#### On ranges: +## On ranges: ```rust for (i,j) in (5..10).enumerate() { println!("i = {} and j = {}", i, j); } ``` + Outputs: -``` + +```rust i = 0 and j = 5 i = 1 and j = 6 i = 2 and j = 7 i = 3 and j = 8 i = 4 and j = 9 ``` + Don't forget to add the parentheses around the range. -#### On iterators: +## On iterators: + ```rust for (linenumber, line) in lines.enumerate() { println!("{}: {}", linenumber, line); } ``` + Outputs: -``` + +```rust 0: Content of line one 1: Content of line two 2: Content of line tree From 90057c29623a945ada73d7156288057e194ef962 Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Sun, 31 May 2015 23:37:22 +0200 Subject: [PATCH 03/10] output code language to text --- src/doc/trpl/for-loops.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/for-loops.md b/src/doc/trpl/for-loops.md index 9cd1689cf3dea..79720a31740e7 100644 --- a/src/doc/trpl/for-loops.md +++ b/src/doc/trpl/for-loops.md @@ -56,7 +56,7 @@ for (i,j) in (5..10).enumerate() { Outputs: -```rust +```text i = 0 and j = 5 i = 1 and j = 6 i = 2 and j = 7 @@ -76,7 +76,7 @@ for (linenumber, line) in lines.enumerate() { Outputs: -```rust +```text 0: Content of line one 1: Content of line two 2: Content of line tree From c4f42a1ab4cf047921018d6ecabbb00ea47fc683 Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Mon, 1 Jun 2015 21:34:31 +0200 Subject: [PATCH 04/10] Added # let lines = "hello\nworld".lines(); to pass the tests --- src/doc/trpl/for-loops.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/doc/trpl/for-loops.md b/src/doc/trpl/for-loops.md index 79720a31740e7..2866cee3a1a63 100644 --- a/src/doc/trpl/for-loops.md +++ b/src/doc/trpl/for-loops.md @@ -69,6 +69,7 @@ Don't forget to add the parentheses around the range. ## On iterators: ```rust +# let lines = "hello\nworld".lines(); for (linenumber, line) in lines.enumerate() { println!("{}: {}", linenumber, line); } From 62f66a68da668e2e11758168036f22e6538a5831 Mon Sep 17 00:00:00 2001 From: Sae-bom Kim Date: Thu, 4 Jun 2015 10:38:49 +0900 Subject: [PATCH 05/10] support aarch64-android raw type definitions --- src/libstd/os/android/raw.rs | 115 +++++++++++++++++++++++++---------- 1 file changed, 82 insertions(+), 33 deletions(-) diff --git a/src/libstd/os/android/raw.rs b/src/libstd/os/android/raw.rs index 538ed7c4688c7..ea80151623bbd 100644 --- a/src/libstd/os/android/raw.rs +++ b/src/libstd/os/android/raw.rs @@ -10,37 +10,86 @@ //! Android-specific raw type definitions -use os::raw::{c_uint, c_uchar, c_ulonglong, c_longlong, c_ulong}; -use os::unix::raw::{uid_t, gid_t}; - -pub type blkcnt_t = u32; -pub type blksize_t = u32; -pub type dev_t = u32; -pub type ino_t = u32; -pub type mode_t = u16; -pub type nlink_t = u16; -pub type off_t = i32; -pub type time_t = i32; - -#[repr(C)] -pub struct stat { - pub st_dev: c_ulonglong, - pub __pad0: [c_uchar; 4], - pub __st_ino: ino_t, - pub st_mode: c_uint, - pub st_nlink: c_uint, - pub st_uid: uid_t, - pub st_gid: gid_t, - pub st_rdev: c_ulonglong, - pub __pad3: [c_uchar; 4], - pub st_size: c_longlong, - pub st_blksize: blksize_t, - pub st_blocks: c_ulonglong, - pub st_atime: time_t, - pub st_atime_nsec: c_ulong, - pub st_mtime: time_t, - pub st_mtime_nsec: c_ulong, - pub st_ctime: time_t, - pub st_ctime_nsec: c_ulong, - pub st_ino: c_ulonglong, +#[doc(inline)] +pub use self::arch::{dev_t, mode_t, blkcnt_t, blksize_t, ino_t, nlink_t, off_t, stat, time_t}; + +#[cfg(target_arch = "arm")] +mod arch { + use os::raw::{c_uint, c_uchar, c_ulonglong, c_longlong, c_ulong}; + use os::unix::raw::{uid_t, gid_t}; + + pub type dev_t = u32; + pub type mode_t = u16; + + pub type blkcnt_t = u32; + pub type blksize_t = u32; + pub type ino_t = u32; + pub type nlink_t = u16; + pub type off_t = i32; + pub type time_t = i32; + + #[repr(C)] + pub struct stat { + pub st_dev: c_ulonglong, + pub __pad0: [c_uchar; 4], + pub __st_ino: ino_t, + pub st_mode: c_uint, + pub st_nlink: c_uint, + pub st_uid: uid_t, + pub st_gid: gid_t, + pub st_rdev: c_ulonglong, + pub __pad3: [c_uchar; 4], + pub st_size: c_longlong, + pub st_blksize: blksize_t, + pub st_blocks: c_ulonglong, + pub st_atime: time_t, + pub st_atime_nsec: c_ulong, + pub st_mtime: time_t, + pub st_mtime_nsec: c_ulong, + pub st_ctime: time_t, + pub st_ctime_nsec: c_ulong, + pub st_ino: c_ulonglong, + } + +} + + +#[cfg(target_arch = "aarch64")] +mod arch { + use os::raw::{c_uchar, c_ulong}; + use os::unix::raw::{uid_t, gid_t}; + + pub type dev_t = u64; + pub type mode_t = u32; + + pub type blkcnt_t = u64; + pub type blksize_t = u32; + pub type ino_t = u64; + pub type nlink_t = u32; + pub type off_t = i64; + pub type time_t = i64; + + #[repr(C)] + pub struct stat { + pub st_dev: dev_t, + pub __pad0: [c_uchar; 4], + pub __st_ino: ino_t, + pub st_mode: mode_t, + pub st_nlink: nlink_t, + pub st_uid: uid_t, + pub st_gid: gid_t, + pub st_rdev: dev_t, + pub __pad3: [c_uchar; 4], + pub st_size: off_t, + pub st_blksize: blksize_t, + pub st_blocks: blkcnt_t, + pub st_atime: time_t, + pub st_atime_nsec: c_ulong, + pub st_mtime: time_t, + pub st_mtime_nsec: c_ulong, + pub st_ctime: time_t, + pub st_ctime_nsec: c_ulong, + pub st_ino: ino_t, + } + } From 2b13b4505865d89e2278f7211a314da47bd03841 Mon Sep 17 00:00:00 2001 From: Andrea Canciani Date: Thu, 4 Jun 2015 15:11:36 +0200 Subject: [PATCH 06/10] Minor fix to docs of constraints on mut/non-mut references The statement is not completely exact, because it is valid to have both 0 non-mutable references and 1 mutable reference. Instead, use the same wording as in mutability.md. --- src/doc/trpl/references-and-borrowing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/references-and-borrowing.md b/src/doc/trpl/references-and-borrowing.md index b69db228f2724..775a6fbd29358 100644 --- a/src/doc/trpl/references-and-borrowing.md +++ b/src/doc/trpl/references-and-borrowing.md @@ -155,7 +155,7 @@ First, any borrow must last for a smaller scope than the owner. Second, you may have one or the other of these two kinds of borrows, but not both at the same time: -* 0 to N references (`&T`) to a resource. +* one or more references (`&T`) to a resource. * exactly one mutable reference (`&mut T`) From 3c0165d59ffc3abe890a0e6512c60e8ab76a16d5 Mon Sep 17 00:00:00 2001 From: Christian Stadelmann Date: Thu, 4 Jun 2015 15:44:30 +0200 Subject: [PATCH 07/10] [Documentation] Use SSL where possible --- src/doc/index.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/doc/index.md b/src/doc/index.md index f561cf5d70f56..fba919b711586 100644 --- a/src/doc/index.md +++ b/src/doc/index.md @@ -25,7 +25,7 @@ series of small examples. If you need help with something, or just want to talk about Rust with others, there are a few places you can do that: -The Rust IRC channels on [irc.mozilla.org](http://irc.mozilla.org/) are the +The Rust IRC channels on [irc.mozilla.org](irc://irc.mozilla.org/) are the fastest way to get help. [`#rust`](http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust) is the general discussion channel, and you'll find people willing to help you with @@ -40,15 +40,15 @@ There's also [`#rust-internals`](http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-internals), which is for discussion of the development of Rust itself. You can also get help on [Stack -Overflow](http://stackoverflow.com/questions/tagged/rust). Searching for your +Overflow](https://stackoverflow.com/questions/tagged/rust). Searching for your problem might reveal someone who has asked it before! -There is an active [subreddit](http://reddit.com/r/rust) with lots of +There is an active [subreddit](https://reddit.com/r/rust) with lots of discussion and news about Rust. -There is also a [user forum](http://users.rust-lang.org), for all -user-oriented discussion, and a [developer -forum](http://internals.rust-lang.org/), where the development of Rust +There is also a [user forum](https://users.rust-lang.org), for all +user-oriented discussion, and a [developer +forum](https://internals.rust-lang.org/), where the development of Rust itself is discussed. # Specification @@ -61,7 +61,7 @@ the language in as much detail as possible is in [the reference](reference.html) Rust is still a young language, so there isn't a ton of tooling yet, but the tools we have are really nice. -[Cargo](http://crates.io) is Rust's package manager, and its website contains +[Cargo](https://crates.io) is Rust's package manager, and its website contains lots of good documentation. [`rustdoc`](book/documentation.html) is used to generate documentation for Rust code. From 2abffd55dba9f9ac45dad3fd0ae568f0f78b99db Mon Sep 17 00:00:00 2001 From: Christian Stadelmann Date: Thu, 4 Jun 2015 15:53:22 +0200 Subject: [PATCH 08/10] [Documentation: Macros] Use some more SSL --- src/doc/trpl/macros.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/doc/trpl/macros.md b/src/doc/trpl/macros.md index e843dbeed3cf4..1317a1490903b 100644 --- a/src/doc/trpl/macros.md +++ b/src/doc/trpl/macros.md @@ -224,7 +224,7 @@ more" match. Both forms optionally include a separator, which can be any token except `+` or `*`. This system is based on -"[Macro-by-Example](http://www.cs.indiana.edu/ftp/techreports/TR206.pdf)" +"[Macro-by-Example](https://www.cs.indiana.edu/ftp/techreports/TR206.pdf)" (PDF link). # Hygiene @@ -319,7 +319,7 @@ syntax context where it was introduced. It’s as though the variable `state` inside `main` is painted a different "color" from the variable `state` inside the macro, and therefore they don’t conflict. -[hygienic macro system]: http://en.wikipedia.org/wiki/Hygienic_macro +[hygienic macro system]: https://en.wikipedia.org/wiki/Hygienic_macro This also restricts the ability of macros to introduce new bindings at the invocation site. Code such as the following will not work: @@ -622,7 +622,7 @@ invocation gives you another opportunity to pattern-match the macro’s arguments. As an extreme example, it is possible, though hardly advisable, to implement -the [Bitwise Cyclic Tag](http://esolangs.org/wiki/Bitwise_Cyclic_Tag) automaton +the [Bitwise Cyclic Tag](https://esolangs.org/wiki/Bitwise_Cyclic_Tag) automaton within Rust’s macro system. ```rust From 4c5029a600bc3c350f2371b736698676600a510b Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 4 Jun 2015 17:30:28 -0400 Subject: [PATCH 09/10] Fix order of rustdoc arguments. rust-example-rendered should be a class, not an id. fixes #26013 --- src/librustdoc/html/markdown.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 66c5a4e0db236..4982215d02f49 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -252,8 +252,8 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result { s.push_str(&format!("{}", Escape(&test))); }); s.push_str(&highlight::highlight(&text, - None, - Some("rust-example-rendered"))); + Some("rust-example-rendered"), + None)); let output = CString::new(s).unwrap(); hoedown_buffer_puts(ob, output.as_ptr()); }) From 536c244be35110482c817e728d476162ddae09b0 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Thu, 4 Jun 2015 19:45:43 -0400 Subject: [PATCH 10/10] Doc-comment fix; trait names are capitalized --- src/libcore/cell.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index d867453008a3f..175dabaf1d2cb 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -38,7 +38,7 @@ //! //! * Introducing inherited mutability roots to shared types. //! * Implementation details of logically-immutable methods. -//! * Mutating implementations of `clone`. +//! * Mutating implementations of `Clone`. //! //! ## Introducing inherited mutability roots to shared types //! @@ -109,7 +109,7 @@ //! } //! ``` //! -//! ## Mutating implementations of `clone` +//! ## Mutating implementations of `Clone` //! //! This is simply a special - but common - case of the previous: hiding mutability for operations //! that appear to be immutable. The `clone` method is expected to not change the source value, and