From 31c3e7ed7838ff6e0f92b26d3f18716d49cee0c6 Mon Sep 17 00:00:00 2001 From: Liigo Zhuang Date: Sat, 25 Apr 2015 06:57:18 +0800 Subject: [PATCH 01/13] rustdoc: change color of trait types Fixes #24441 --- src/librustdoc/html/static/main.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/main.css b/src/librustdoc/html/static/main.css index c94dbc1510332..b907e9e20b698 100644 --- a/src/librustdoc/html/static/main.css +++ b/src/librustdoc/html/static/main.css @@ -392,7 +392,7 @@ a { text-decoration: underline; } -.content span.trait, .content a.trait, .block a.current.trait { color: #ed9603; } +.content span.trait, .content a.trait, .block a.current.trait { color: #8866ff; } .content span.mod, .content a.mod, block a.current.mod { color: #4d76ae; } .content span.enum, .content a.enum, .block a.current.enum { color: #5e9766; } .content span.struct, .content a.struct, .block a.current.struct { color: #e53700; } From 4ade7080c37b3ba27b018750823fd6f9d0adcc0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rory=20O=E2=80=99Kane?= Date: Fri, 24 Apr 2015 20:29:28 -0400 Subject: [PATCH 02/13] =?UTF-8?q?In=20[-]=20doc=20buttons,=20change=20hyph?= =?UTF-8?q?en=20=E2=80=98-=E2=80=99=20to=20minus=20=E2=80=98=E2=88=92?= =?UTF-8?q?=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The minus sign ‘−’ is the same width as the plus sign ‘+’, so the button’s transition between the two symbols will look more smooth. --- src/librustdoc/html/static/main.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 56cea50a50239..328eef1b5a298 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -808,7 +808,7 @@ $("#toggle-all-docs").on("click", function() { var toggle = $("#toggle-all-docs"); - if (toggle.html() == "[-]") { + if (toggle.html() == "[−]") { toggle.html("[+]"); toggle.attr("title", "expand all docs"); $(".docblock").hide(); @@ -816,12 +816,12 @@ $(".toggle-wrapper").addClass("collapsed"); $(".collapse-toggle").children(".inner").html("+"); } else { - toggle.html("[-]"); + toggle.html("[−]"); toggle.attr("title", "collapse all docs"); $(".docblock").show(); $(".toggle-label").hide(); $(".toggle-wrapper").removeClass("collapsed"); - $(".collapse-toggle").children(".inner").html("-"); + $(".collapse-toggle").children(".inner").html("−"); } }); @@ -840,7 +840,7 @@ } else { relatedDoc.slideDown({duration:'fast', easing:'linear'}); toggle.parent(".toggle-wrapper").removeClass("collapsed"); - toggle.children(".inner").html("-"); + toggle.children(".inner").html("−"); toggle.children(".toggle-label").hide(); } } @@ -848,7 +848,7 @@ $(function() { var toggle = $("", {'href': 'javascript:void(0)', 'class': 'collapse-toggle'}) - .html("[-]"); + .html("[]"); $(".method").each(function() { if ($(this).next().is(".docblock") || From 84ef3b53517e2ed1148e6d4214c0c97c2328ead0 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Sun, 26 Apr 2015 22:13:58 +0200 Subject: [PATCH 03/13] collections: Improve example for as_string and as_vec --- src/libcollections/string.rs | 9 +++++---- src/libcollections/vec.rs | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index a37a26ef22ac3..be6405dc85a14 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -951,12 +951,13 @@ impl<'a> Deref for DerefString<'a> { /// # #![feature(collections)] /// use std::string::as_string; /// -/// fn string_consumer(s: String) { -/// assert_eq!(s, "foo".to_string()); +/// // Let's pretend we have a function that requires `&String` +/// fn string_consumer(s: &String) { +/// assert_eq!(s, "foo"); /// } /// -/// let string = as_string("foo").clone(); -/// string_consumer(string); +/// // Provide a `&String` from a `&str` without allocating +/// string_consumer(&as_string("foo")); /// ``` #[unstable(feature = "collections")] pub fn as_string<'a>(x: &'a str) -> DerefString<'a> { diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 526150915a705..98819e0d7ce6f 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1919,6 +1919,22 @@ impl<'a, T> Drop for DerefVec<'a, T> { } /// Converts a slice to a wrapper type providing a `&Vec` reference. +/// +/// # Examples +/// +/// ``` +/// # #![feature(collections)] +/// use std::vec::as_vec; +/// +/// // Let's pretend we have a function that requires `&Vec` +/// fn vec_consumer(s: &Vec) { +/// assert_eq!(s, &[1, 2, 3]); +/// } +/// +/// // Provide a `&Vec` from a `&[i32]` without allocating +/// let values = [1, 2, 3]; +/// vec_consumer(&as_vec(&values)); +/// ``` #[unstable(feature = "collections")] pub fn as_vec<'a, T>(x: &'a [T]) -> DerefVec<'a, T> { unsafe { From 57284e68803c820ea8d453ed9711e065d2fb3b49 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 26 Apr 2015 23:18:19 -0400 Subject: [PATCH 04/13] Make From::from example more idiomatic / simpler --- src/libcore/convert.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index d9cda58d9ebed..d3de77a9241e3 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -83,10 +83,8 @@ pub trait Into: Sized { /// `String` implements `From<&str>`: /// /// ``` -/// let s = "hello"; /// let string = "hello".to_string(); -/// -/// let other_string: String = From::from(s); +/// let other_string = String::from("hello"); /// /// assert_eq!(string, other_string); /// ``` From 5ed3ac99f4228e35940f61533b7185234764e8a8 Mon Sep 17 00:00:00 2001 From: Richo Healey Date: Sun, 26 Apr 2015 21:17:14 -0700 Subject: [PATCH 05/13] thread: right now you can't actually set those printers --- src/libstd/thread/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 9168a716d4380..383726b3e8370 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -115,8 +115,7 @@ //! ## Configuring threads //! //! A new thread can be configured before it is spawned via the `Builder` type, -//! which currently allows you to set the name, stack size, and writers for -//! `println!` and `panic!` for the child thread: +//! which currently allows you to set the name and stack size for the child thread: //! //! ```rust //! # #![allow(unused_must_use)] From 02428dfde5b1dc326444943dc3c298731945272e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rory=20O=E2=80=99Kane?= Date: Mon, 27 Apr 2015 02:26:58 -0400 Subject: [PATCH 06/13] Change hyphen to minus in HTML template too --- src/librustdoc/html/render.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 1993f03efd1fa..cf975084e2b71 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1460,7 +1460,7 @@ impl<'a> fmt::Display for Item<'a> { try!(write!(fmt, "")); try!(write!(fmt, r##" - [-] + [−] "##)); // Write `src` tag From 72e8f7b1ab344546e7b073317d4f696acab1a5f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rory=20O=E2=80=99Kane?= Date: Mon, 27 Apr 2015 02:41:45 -0400 Subject: [PATCH 07/13] =?UTF-8?q?Change=20literal=20minus=20=E2=80=98?= =?UTF-8?q?=E2=88=92=E2=80=99=20to=20HTML=20entity=20=E2=80=98−?= =?UTF-8?q?=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So that if people accidentally delete the character, they won’t re-type it as a hyphen, which would cause bugs. I changed ‘+’ too, even though it won’t be re-typed incorrectly, so that it is easier to see when plus is used as a symbol for the button, and when it is used as an operator in code. It also makes it clearer that the use of an entity for minus is on purpose, so people won’t be tempted to replace the entity incorrectly with a hyphen character. --- src/librustdoc/html/render.rs | 2 +- src/librustdoc/html/static/main.js | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index cf975084e2b71..a2cfb533c1a00 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1460,7 +1460,7 @@ impl<'a> fmt::Display for Item<'a> { try!(write!(fmt, "")); try!(write!(fmt, r##" - [−] + [−] "##)); // Write `src` tag diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 328eef1b5a298..c2a59278a86dc 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -808,20 +808,20 @@ $("#toggle-all-docs").on("click", function() { var toggle = $("#toggle-all-docs"); - if (toggle.html() == "[−]") { - toggle.html("[+]"); + if (toggle.html() == "[−]") { + toggle.html("[+]"); toggle.attr("title", "expand all docs"); $(".docblock").hide(); $(".toggle-label").show(); $(".toggle-wrapper").addClass("collapsed"); - $(".collapse-toggle").children(".inner").html("+"); + $(".collapse-toggle").children(".inner").html("+"); } else { - toggle.html("[−]"); + toggle.html("[−]"); toggle.attr("title", "collapse all docs"); $(".docblock").show(); $(".toggle-label").hide(); $(".toggle-wrapper").removeClass("collapsed"); - $(".collapse-toggle").children(".inner").html("−"); + $(".collapse-toggle").children(".inner").html("−"); } }); @@ -835,12 +835,12 @@ if (relatedDoc.is(":visible")) { relatedDoc.slideUp({duration:'fast', easing:'linear'}); toggle.parent(".toggle-wrapper").addClass("collapsed"); - toggle.children(".inner").html("+"); + toggle.children(".inner").html("+"); toggle.children(".toggle-label").fadeIn(); } else { relatedDoc.slideDown({duration:'fast', easing:'linear'}); toggle.parent(".toggle-wrapper").removeClass("collapsed"); - toggle.children(".inner").html("−"); + toggle.children(".inner").html("−"); toggle.children(".toggle-label").hide(); } } @@ -848,7 +848,7 @@ $(function() { var toggle = $("", {'href': 'javascript:void(0)', 'class': 'collapse-toggle'}) - .html("[]"); + .html("[]"); $(".method").each(function() { if ($(this).next().is(".docblock") || From 709f3c51302ca86617cca4a67648302c5088381c Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Mon, 27 Apr 2015 11:39:42 +0100 Subject: [PATCH 08/13] Update reference.md: string literals section Remove the name "multi-line string literal" since the rule appears to affect each line-break individually rather than the whole string literal. Re-word, and remove the stray reference to raw strings. --- src/doc/reference.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 7c9cca90edda7..a7ed05c5a23fa 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -192,13 +192,13 @@ which must be _escaped_ by a preceding `U+005C` character (`\`). A _string literal_ is a sequence of any Unicode characters enclosed within two `U+0022` (double-quote) characters, with the exception of `U+0022` itself, -which must be _escaped_ by a preceding `U+005C` character (`\`), or a _raw -string literal_. +which must be _escaped_ by a preceding `U+005C` character (`\`). -A multi-line string literal may be defined by terminating each line with a -`U+005C` character (`\`) immediately before the newline. This causes the -`U+005C` character, the newline, and all whitespace at the beginning of the -next line to be ignored. +Line-break characters are allowed in string literals. Normally they represent +themselves (i.e. no translation), but as a special exception, when a `U+005C` +character (`\`) occurs immediately before the newline, the `U+005C` character, +the newline, and all whitespace at the beginning of the next line are ignored. +Thus `a` and `b` are equal: ```rust let a = "foobar"; From cf650a217495940bdf3f8a843f5dd959b6e37b5e Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Mon, 27 Apr 2015 12:24:47 +0100 Subject: [PATCH 09/13] Update reference.md: floating-point section Clarify type inference of floating-point literals --- src/doc/reference.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index a7ed05c5a23fa..848c0df10ee9a 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -366,11 +366,19 @@ A _floating-point literal_ has one of two forms: optionally followed by another decimal literal, with an optional _exponent_. * A single _decimal literal_ followed by an _exponent_. -By default, a floating-point literal has a generic type, and, like integer -literals, the type must be uniquely determined from the context. There are two valid +Like integer literals, a floating-point literal may be followed by a +suffix, so long as the pre-suffix part does not end with `U+002E` (`.`). +The suffix forcibly sets the type of the literal. There are two valid _floating-point suffixes_, `f32` and `f64` (the 32-bit and 64-bit floating point types), which explicitly determine the type of the literal. +The type of an _unsuffixed_ floating-point literal is determined by type +inference. If a floating-point type can be _uniquely_ determined from the +surrounding program context, the unsuffixed floating-point literal has that type. +If the program context underconstrains the type, it defaults to double-precision `f64`; +if the program context overconstrains the type, it is considered a static type +error. + Examples of floating-point literals of various forms: ``` From 7335c9f48fc9ba491e054ea98950b8b2eb723c19 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Mon, 27 Apr 2015 14:09:38 +0200 Subject: [PATCH 10/13] book: improve Vec intro --- src/doc/trpl/vectors.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/vectors.md b/src/doc/trpl/vectors.md index 28d815c4eb735..6170bdb86eaa3 100644 --- a/src/doc/trpl/vectors.md +++ b/src/doc/trpl/vectors.md @@ -1,8 +1,9 @@ % Vectors A ‘vector’ is a dynamic or ‘growable’ array, implemented as the standard -library type [`Vec`][vec]. That `` is a [generic][generic], meaning we -can have vectors of any type. Vectors always allocate their data on the heap. +library type [`Vec`][vec]. The `T` means that we can have vectors +of any type (see the chapter on [generics][generic] for more). +Vectors always allocate their data on the heap. You can create them with the `vec!` macro: ```rust From 38042d1e18bc37dac34c74e094a3678b4c613a7a Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 27 Apr 2015 14:22:15 +0530 Subject: [PATCH 11/13] trpl: clarify lib.rs vs main.rs --- src/doc/trpl/hello-cargo.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/doc/trpl/hello-cargo.md b/src/doc/trpl/hello-cargo.md index 6967532a44735..d547451fccec2 100644 --- a/src/doc/trpl/hello-cargo.md +++ b/src/doc/trpl/hello-cargo.md @@ -32,6 +32,13 @@ $ mkdir src $ mv main.rs src/main.rs ``` +Note that since we're creating an executable, we used `main.rs`. If we +want to make a library instead, we should use `lib.rs`. +Custom file locations for the entry point can be specified +with a [`[[lib]]` or `[[bin]]`][crates-custom] key in the TOML file described below. + +[crates-custom]: http://doc.crates.io/manifest.html#configuring-a-target + Cargo expects your source files to live inside a `src` directory. That leaves the top level for other things, like READMEs, license information, and anything not related to your code. Cargo helps us keep our projects nice and tidy. A From 14a6a9f5e22a4577e4a70c7cb88d94f821f46aa3 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Mon, 27 Apr 2015 15:42:46 +0200 Subject: [PATCH 12/13] reference: block-comment -> block comment --- src/doc/reference.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 7c9cca90edda7..60c335a376209 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -84,7 +84,7 @@ that does _not_ occur in the set of [keywords](#keywords). ## Comments Comments in Rust code follow the general C++ style of line (`//`) and -block-comment (`/* ... */`) forms. Nested block comments are supported. +block (`/* ... */`) comment forms. Nested block comments are supported. Line comments beginning with exactly _three_ slashes (`///`), and block comments beginning with exactly one repeated asterisk in the block-open From 36cf51dc3a53ab32fe587e7b0b62af0f2b3b8ad0 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Mon, 27 Apr 2015 16:11:46 +0200 Subject: [PATCH 13/13] doc: it is 'index', not 'i' --- src/libcollections/vec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index c8a8498d2f929..57c42b89afcdb 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -536,7 +536,7 @@ impl Vec { /// /// # Panics /// - /// Panics if `i` is out of bounds. + /// Panics if `index` is out of bounds. /// /// # Examples ///