From 0d033dd7c259bb52d6fdd01f08c1762db17ea217 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Tue, 9 Jun 2015 00:00:20 +0200 Subject: [PATCH 01/10] reference: get consistent by removing unneeded whitespace --- src/doc/reference.md | 1 - 1 file changed, 1 deletion(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index d56ecb360cfe..154bb300f61a 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -1367,7 +1367,6 @@ Traits can include default implementations of methods, as in: ``` trait Foo { fn bar(&self); - fn baz(&self) { println!("We called baz."); } } ``` From 0a70c94d6881e2e8cf8f436b077ed54df738aa9e Mon Sep 17 00:00:00 2001 From: simplex Date: Tue, 9 Jun 2015 13:08:16 -0300 Subject: [PATCH 02/10] Semantic accuracy in borrow scope rules. The text claimed 'any borrow must last for a _smaller_ scope than the owner', however the accurate way of describing the comparison is inclusive (i.e., 'less than or equal to' vs. 'less than'). --- src/doc/trpl/references-and-borrowing.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/doc/trpl/references-and-borrowing.md b/src/doc/trpl/references-and-borrowing.md index 775a6fbd2935..b27db2ab7bea 100644 --- a/src/doc/trpl/references-and-borrowing.md +++ b/src/doc/trpl/references-and-borrowing.md @@ -151,9 +151,9 @@ As it turns out, there are rules. Here’s the rules about borrowing in Rust: -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: +First, any borrow must last for a scope no greater than that of the owner. +Second, you may have one or the other of these two kinds of borrows, but not +both at the same time: * one or more references (`&T`) to a resource. * exactly one mutable reference (`&mut T`) From 24c596c650126116bb5c484666e8c9c34f8da562 Mon Sep 17 00:00:00 2001 From: Andrew Straw Date: Tue, 9 Jun 2015 20:47:51 +0200 Subject: [PATCH 03/10] fix example in comments about demangling --- src/libstd/sys/common/backtrace.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/sys/common/backtrace.rs b/src/libstd/sys/common/backtrace.rs index 580d970af0c3..00932712a07a 100644 --- a/src/libstd/sys/common/backtrace.rs +++ b/src/libstd/sys/common/backtrace.rs @@ -27,7 +27,7 @@ pub const HEX_WIDTH: usize = 10; // 2. For each element of the path, emit the length plus the element // 3. End the path with "E" // -// For example, "_ZN4testE" => "test" and "_ZN3foo3bar" => "foo::bar". +// For example, "_ZN4testE" => "test" and "_ZN3foo3barE" => "foo::bar". // // We're the ones printing our backtraces, so we can't rely on anything else to // demangle our symbols. It's *much* nicer to look at demangled symbols, so From 1fff553fe79659193d535a0f5acf43ed08339ca8 Mon Sep 17 00:00:00 2001 From: Andrew Straw Date: Tue, 9 Jun 2015 20:49:52 +0200 Subject: [PATCH 04/10] fix comments in example about types --- src/librustc/middle/traits/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/middle/traits/README.md b/src/librustc/middle/traits/README.md index 9c47d7f217aa..853d12172af5 100644 --- a/src/librustc/middle/traits/README.md +++ b/src/librustc/middle/traits/README.md @@ -120,7 +120,7 @@ implement `Convert` like so: ```rust impl Convert for int { ... } // int -> uint -impl Convert for uint { ... } // uint -> uint +impl Convert for uint { ... } // uint -> int ``` Now imagine there is some code like the following: From f62ad7d7dfb3dc693a6119ad0791c647ec0fb498 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 9 Jun 2015 14:59:25 -0400 Subject: [PATCH 05/10] remove stuff about #define This obscures more than it helps. Fixes #25573 --- src/doc/trpl/const-and-static.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/doc/trpl/const-and-static.md b/src/doc/trpl/const-and-static.md index f309dd0fad6d..83461feba40d 100644 --- a/src/doc/trpl/const-and-static.md +++ b/src/doc/trpl/const-and-static.md @@ -78,7 +78,3 @@ Almost always, if you can choose between the two, choose `const`. It’s pretty rare that you actually want a memory location associated with your constant, and using a const allows for optimizations like constant propagation not only in your crate but downstream crates. - -A const can be thought of as a `#define` in C: it has metadata overhead but it -has no runtime overhead. “Should I use a #define or a static in C,” is largely -the same question as whether you should use a const or a static in Rust. From a9899a73533c542efcc797405e3c09882da9d7fa Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 9 Jun 2015 15:17:25 -0400 Subject: [PATCH 06/10] Clarify confusing sentence in TRPL: FFI After talking with @graydon on #rust-internals, this is hopefully clarifying. Fixes #25586 --- src/doc/trpl/ffi.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/ffi.md b/src/doc/trpl/ffi.md index 9ede835e521c..8077f04ed608 100644 --- a/src/doc/trpl/ffi.md +++ b/src/doc/trpl/ffi.md @@ -342,8 +342,10 @@ Note that frameworks are only available on OSX targets. The different `kind` values are meant to differentiate how the native library participates in linkage. From a linkage perspective, the rust compiler creates two flavors of artifacts: partial (rlib/staticlib) and final (dylib/binary). -Native dynamic libraries and frameworks are propagated to the final artifact -boundary, while static libraries are not propagated at all. +Native dynamic library and framework dependencies are propagated to the final +artifact boundary, while static library dependencies are not propagated at +all, because the static libraries are integrated directly into the subsequent +artifact. A few examples of how this model can be used are: From e12c4205220a6e1114493aa4501cc04e48d8693b Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 9 Jun 2015 15:24:44 -0400 Subject: [PATCH 07/10] Expand a bit on clone() in Dining Philosophers Fixes #25597 --- src/doc/trpl/dining-philosophers.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/doc/trpl/dining-philosophers.md b/src/doc/trpl/dining-philosophers.md index a18d9bb442dd..b24d50c890da 100644 --- a/src/doc/trpl/dining-philosophers.md +++ b/src/doc/trpl/dining-philosophers.md @@ -674,9 +674,13 @@ let handles: Vec<_> = philosophers.into_iter().map(|p| { Finally, inside of our `map()`/`collect()` loop, we call `table.clone()`. The `clone()` method on `Arc` is what bumps up the reference count, and when it -goes out of scope, it decrements the count. You’ll notice we can introduce a -new binding to `table` here, and it will shadow the old one. This is often used -so that you don’t need to come up with two unique names. +goes out of scope, it decrements the count. This is needed so that we know how +many references to `table` exist across our threads. If we didn’t have a count, +we wouldn’t know how to deallocate it. + +You’ll notice we can introduce a new binding to `table` here, and it will +shadow the old one. This is often used so that you don’t need to come up with +two unique names. With this, our program works! Only two philosophers can eat at any one time, and so you’ll get some output like this: From a0b08f387b5f383fb4a135a4cd68f0d3842743d2 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 9 Jun 2015 14:32:10 -0400 Subject: [PATCH 08/10] Explain interaction with if and | in patterns Fixes #26012 --- src/doc/trpl/patterns.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/doc/trpl/patterns.md b/src/doc/trpl/patterns.md index 93df0f19e8ee..0f356d75abc8 100644 --- a/src/doc/trpl/patterns.md +++ b/src/doc/trpl/patterns.md @@ -154,6 +154,31 @@ match x { This prints `Got an int!`. +If you’re using `if` with multiple patterns, the `if` applies to both sides: + +```rust +let x = 4; +let y = false; + +match x { + 4 | 5 if y => println!("yes"), + _ => println!("no"), +} +``` + +This prints `no`, because the `if` applies to the whole of `4 | 5`, and not to +just the `5`, In other words, the the precedence of `if` behaves like this: + +```text +(4 | 5) if y => ... +``` + +not this: + +```text +4 | (5 if y) => ... +``` + # ref and ref mut If you want to get a [reference][ref], use the `ref` keyword: From a95b48c2dd921fa37f54ee42e14e66a185951e58 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 9 Jun 2015 15:49:54 -0400 Subject: [PATCH 09/10] Fix some copyediting in TRPL: method-syntax As this example got changed, we stopped showing how to return self as the first example, so this text is outdated. Fixes #25803 --- src/doc/trpl/method-syntax.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/method-syntax.md b/src/doc/trpl/method-syntax.md index 1f694f71a883..1afa622db7dd 100644 --- a/src/doc/trpl/method-syntax.md +++ b/src/doc/trpl/method-syntax.md @@ -86,8 +86,8 @@ impl Circle { # 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 -can do it by returning `self`. +original example, `foo.bar().baz()`? This is called ‘method chaining’. Let’s +look at an example: ```rust struct Circle { From 9db94498363b4cdf9252084a576bfdb5f13b082f Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 9 Jun 2015 16:30:39 -0400 Subject: [PATCH 10/10] Make note about static and dtors Fixes #25851 --- src/doc/trpl/const-and-static.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/doc/trpl/const-and-static.md b/src/doc/trpl/const-and-static.md index f309dd0fad6d..3073a66cbfd2 100644 --- a/src/doc/trpl/const-and-static.md +++ b/src/doc/trpl/const-and-static.md @@ -64,7 +64,10 @@ unsafe { [unsafe]: unsafe.html -Furthermore, any type stored in a `static` must be `Sync`. +Furthermore, any type stored in a `static` must be `Sync`, and may not have +a [`Drop`][drop] implementation. + +[drop]: drop.html # Initializing