From 994ccd30a09f57fb0055cf987f006fa19206902d Mon Sep 17 00:00:00 2001 From: Ingo Blechschmidt Date: Fri, 6 Feb 2015 23:14:51 +0100 Subject: [PATCH 1/3] Note that types do not have to be declared in closures Without such a clarification, people who know and love closures (for instance programmers with a Haskell background) might fear that types would have to be declared in closures and that therefore using closures would be much more unwieldy. --- src/doc/trpl/functions.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/doc/trpl/functions.md b/src/doc/trpl/functions.md index d0ecb6067955d..c8b79232aa90b 100644 --- a/src/doc/trpl/functions.md +++ b/src/doc/trpl/functions.md @@ -75,7 +75,8 @@ This is a deliberate design decision. While full-program inference is possible, languages which have it, like Haskell, often suggest that documenting your types explicitly is a best-practice. We agree that forcing functions to declare types while allowing for inference inside of function bodies is a wonderful -sweet spot between full inference and no inference. +sweet spot between full inference and no inference. (For closures, i.e. unnamed +functions, types do not have to be declared.) What about returning a value? Here's a function that adds one to an integer: From 526e74884640ded4e7d32d3b73a03c395f10991b Mon Sep 17 00:00:00 2001 From: Ingo Blechschmidt Date: Sat, 7 Feb 2015 00:39:28 +0100 Subject: [PATCH 2/3] Fix several tiny typos --- src/doc/trpl/documentation.md | 2 +- src/doc/trpl/macros.md | 6 +++--- src/doc/trpl/match.md | 2 +- src/doc/trpl/method-syntax.md | 2 +- src/doc/trpl/more-strings.md | 2 +- src/doc/trpl/ownership.md | 2 +- src/doc/trpl/unsafe.md | 8 ++++---- src/libcore/iter.rs | 4 ++-- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/doc/trpl/documentation.md b/src/doc/trpl/documentation.md index 0b686eb76dbfb..46dadbfe0cb09 100644 --- a/src/doc/trpl/documentation.md +++ b/src/doc/trpl/documentation.md @@ -15,7 +15,7 @@ comments": // the "link" crate attribute is currently required for rustdoc, but normally // isn't needed. #![crate_id = "universe"] -#![crate_type="lib"] +#![crate_type = "lib"] //! Tools for dealing with universes (this is a doc comment, and is shown on //! the crate index page. The ! makes it apply to the parent of the comment, diff --git a/src/doc/trpl/macros.md b/src/doc/trpl/macros.md index f429e9df19657..14c57014e38e0 100644 --- a/src/doc/trpl/macros.md +++ b/src/doc/trpl/macros.md @@ -163,7 +163,7 @@ The syntax `$(...)*` on the left-hand side of the `=>` in a macro definition accepts zero or more occurrences of its contents. It works much like the `*` operator in regular expressions. It also supports a separator token (a comma-separated list could be written `$(...),*`), and `+` -instead of `*` to mean "at least one". +instead of `*` to mean "at least one." ~~~~ # enum T { SpecialA(u32), SpecialB(u32), SpecialC(u32), SpecialD(u32) } @@ -195,7 +195,7 @@ As the above example demonstrates, `$(...)*` is also valid on the right-hand side of a macro definition. The behavior of `*` in transcription, especially in cases where multiple `*`s are nested, and multiple different names are involved, can seem somewhat magical and unintuitive at first. The -system that interprets them is called "Macro By Example". The two rules to +system that interprets them is called "Macro By Example." The two rules to keep in mind are (1) the behavior of `$(...)*` is to walk through one "layer" of repetitions for all of the `$name`s it contains in lockstep, and (2) each `$name` must be under at least as many `$(...)*`s as it was matched against. @@ -309,7 +309,7 @@ there is a solution. A macro may accept multiple different input grammars. The first one to successfully match the actual argument to a macro invocation is the one that -"wins". +"wins." In the case of the example above, we want to write a recursive macro to process the semicolon-terminated lines, one-by-one. So, we want the following diff --git a/src/doc/trpl/match.md b/src/doc/trpl/match.md index 73bc775a1b290..26aa6e26b30ca 100644 --- a/src/doc/trpl/match.md +++ b/src/doc/trpl/match.md @@ -23,7 +23,7 @@ match x { `match` takes an expression and then branches based on its value. Each *arm* of the branch is of the form `val => expression`. When the value matches, that arm's expression will be evaluated. It's called `match` because of the term 'pattern -matching', which `match` is an implementation of. +matching,' which `match` is an implementation of. So what's the big advantage here? Well, there are a few. First of all, `match` enforces *exhaustiveness checking*. Do you see that last arm, the one with the diff --git a/src/doc/trpl/method-syntax.md b/src/doc/trpl/method-syntax.md index e6570c2ee74c8..6da834b617c24 100644 --- a/src/doc/trpl/method-syntax.md +++ b/src/doc/trpl/method-syntax.md @@ -61,7 +61,7 @@ multiplications later, and we have our area. ## Chaining method calls So, now we know how to call a method, such as `foo.bar()`. But what about our -original example, `foo.bar().baz()`? This is called 'method chaining', and we +original example, `foo.bar().baz()`? This is called 'method chaining,' and we can do it by returning `self`. ``` diff --git a/src/doc/trpl/more-strings.md b/src/doc/trpl/more-strings.md index 986ad23c665a7..9af4304253c94 100644 --- a/src/doc/trpl/more-strings.md +++ b/src/doc/trpl/more-strings.md @@ -14,7 +14,7 @@ Rust has two main types of strings: `&str` and `String`. # &str -The first kind is a `&str`. This is pronounced a 'string slice'. +The first kind is a `&str`. This is pronounced a 'string slice.' String literals are of the type `&str`: ``` diff --git a/src/doc/trpl/ownership.md b/src/doc/trpl/ownership.md index 9e3a3f12d1d21..e1d6bd697d4a9 100644 --- a/src/doc/trpl/ownership.md +++ b/src/doc/trpl/ownership.md @@ -293,7 +293,7 @@ struct Foo<'a> { } fn main() { - let y = &5; // this is the same as `let _y = 5; let y = &_y; + let y = &5; // this is the same as `let _y = 5; let y = &_y;` let f = Foo { x: y }; println!("{}", f.x); diff --git a/src/doc/trpl/unsafe.md b/src/doc/trpl/unsafe.md index 2bd86fa987f4b..ee498f25690a1 100644 --- a/src/doc/trpl/unsafe.md +++ b/src/doc/trpl/unsafe.md @@ -308,7 +308,7 @@ crate to allow) and of course requires an `unsafe` block. ## Assembly template The `assembly template` is the only required parameter and must be a -literal string (i.e `""`) +literal string (i.e. `""`) ``` #![feature(asm)] @@ -412,7 +412,7 @@ memory, `memory` should also be specified. ## Options The last section, `options` is specific to Rust. The format is comma -separated literal strings (i.e `:"foo", "bar", "baz"`). It's used to +separated literal strings (i.e. `:"foo", "bar", "baz"`). It's used to specify some extra info about the inline assembly: Current valid options are: @@ -420,7 +420,7 @@ Current valid options are: 1. *volatile* - specifying this is analogous to `__asm__ __volatile__ (...)` in gcc/clang. 2. *alignstack* - certain instructions expect the stack to be - aligned a certain way (i.e SSE) and specifying this indicates to + aligned a certain way (i.e. SSE) and specifying this indicates to the compiler to insert its usual stack alignment code 3. *intel* - use intel syntax instead of the default AT&T. @@ -649,7 +649,7 @@ functionality that isn't hard-coded into the language, but is implemented in libraries, with a special marker to tell the compiler it exists. The marker is the attribute `#[lang="..."]` and there are various different values of `...`, i.e. various different "lang -items". +items." For example, `Box` pointers require two lang items, one for allocation and one for deallocation. A freestanding program that uses the `Box` diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 23157072d536b..2c0691dede484 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -2348,7 +2348,7 @@ impl Iterator for Unfold where F: FnMut(&mut St) -> Option { /// iteration #[derive(Clone)] #[unstable(feature = "core", - reason = "may be renamed or replaced by range notation adapaters")] + reason = "may be renamed or replaced by range notation adapters")] pub struct Counter { /// The current state the counter is at (next value to be yielded) state: A, @@ -2359,7 +2359,7 @@ pub struct Counter { /// Creates a new counter with the specified start/step #[inline] #[unstable(feature = "core", - reason = "may be renamed or replaced by range notation adapaters")] + reason = "may be renamed or replaced by range notation adapters")] pub fn count(start: A, step: A) -> Counter { Counter{state: start, step: step} } From 918d097c8e6fb45a0160b23898dc74062f88a422 Mon Sep 17 00:00:00 2001 From: Ingo Blechschmidt Date: Mon, 16 Feb 2015 23:13:58 +0100 Subject: [PATCH 3/3] Tiny typo changes (per discussion in pull request #22027) --- src/doc/trpl/documentation.md | 2 +- src/doc/trpl/functions.md | 3 +-- src/doc/trpl/match.md | 2 +- src/doc/trpl/method-syntax.md | 2 +- src/doc/trpl/more-strings.md | 2 +- src/doc/trpl/unsafe.md | 4 ++-- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/doc/trpl/documentation.md b/src/doc/trpl/documentation.md index 46dadbfe0cb09..0de15f52e192d 100644 --- a/src/doc/trpl/documentation.md +++ b/src/doc/trpl/documentation.md @@ -15,7 +15,7 @@ comments": // the "link" crate attribute is currently required for rustdoc, but normally // isn't needed. #![crate_id = "universe"] -#![crate_type = "lib"] +#![crate_type= lib"] //! Tools for dealing with universes (this is a doc comment, and is shown on //! the crate index page. The ! makes it apply to the parent of the comment, diff --git a/src/doc/trpl/functions.md b/src/doc/trpl/functions.md index c8b79232aa90b..d0ecb6067955d 100644 --- a/src/doc/trpl/functions.md +++ b/src/doc/trpl/functions.md @@ -75,8 +75,7 @@ This is a deliberate design decision. While full-program inference is possible, languages which have it, like Haskell, often suggest that documenting your types explicitly is a best-practice. We agree that forcing functions to declare types while allowing for inference inside of function bodies is a wonderful -sweet spot between full inference and no inference. (For closures, i.e. unnamed -functions, types do not have to be declared.) +sweet spot between full inference and no inference. What about returning a value? Here's a function that adds one to an integer: diff --git a/src/doc/trpl/match.md b/src/doc/trpl/match.md index 26aa6e26b30ca..73bc775a1b290 100644 --- a/src/doc/trpl/match.md +++ b/src/doc/trpl/match.md @@ -23,7 +23,7 @@ match x { `match` takes an expression and then branches based on its value. Each *arm* of the branch is of the form `val => expression`. When the value matches, that arm's expression will be evaluated. It's called `match` because of the term 'pattern -matching,' which `match` is an implementation of. +matching', which `match` is an implementation of. So what's the big advantage here? Well, there are a few. First of all, `match` enforces *exhaustiveness checking*. Do you see that last arm, the one with the diff --git a/src/doc/trpl/method-syntax.md b/src/doc/trpl/method-syntax.md index 6da834b617c24..e6570c2ee74c8 100644 --- a/src/doc/trpl/method-syntax.md +++ b/src/doc/trpl/method-syntax.md @@ -61,7 +61,7 @@ multiplications later, and we have our area. ## Chaining method calls So, now we know how to call a method, such as `foo.bar()`. But what about our -original example, `foo.bar().baz()`? This is called 'method chaining,' and we +original example, `foo.bar().baz()`? This is called 'method chaining', and we can do it by returning `self`. ``` diff --git a/src/doc/trpl/more-strings.md b/src/doc/trpl/more-strings.md index 9af4304253c94..986ad23c665a7 100644 --- a/src/doc/trpl/more-strings.md +++ b/src/doc/trpl/more-strings.md @@ -14,7 +14,7 @@ Rust has two main types of strings: `&str` and `String`. # &str -The first kind is a `&str`. This is pronounced a 'string slice.' +The first kind is a `&str`. This is pronounced a 'string slice'. String literals are of the type `&str`: ``` diff --git a/src/doc/trpl/unsafe.md b/src/doc/trpl/unsafe.md index ee498f25690a1..1d4b0cb0e1f35 100644 --- a/src/doc/trpl/unsafe.md +++ b/src/doc/trpl/unsafe.md @@ -648,8 +648,8 @@ The `rustc` compiler has certain pluggable operations, that is, functionality that isn't hard-coded into the language, but is implemented in libraries, with a special marker to tell the compiler it exists. The marker is the attribute `#[lang="..."]` and there are -various different values of `...`, i.e. various different "lang -items." +various different values of `...`, i.e. various different 'lang +items'. For example, `Box` pointers require two lang items, one for allocation and one for deallocation. A freestanding program that uses the `Box`