From cb7d91488043df645b23a9ffd25997386d00e425 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 3 Jun 2015 15:24:35 -0700 Subject: [PATCH 01/10] mk: Compile C code on MSVC with /MD On MSVC there are two ways that the CRT can be linked, either statically or dynamically. Each object file produced by the compiler is compiled against msvcrt (a dll) or libcmt (a static library). When the linker is dealing with more than one object file, it requires that all object files link to the same CRT, or else the linker will spit out some errors. For now, compile code with `-MD` as it seems to appear more often in C libraries so we'll stick with the same trend. --- mk/cfg/x86_64-pc-windows-msvc.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mk/cfg/x86_64-pc-windows-msvc.mk b/mk/cfg/x86_64-pc-windows-msvc.mk index 1e1906a298084..c718c19d366ce 100644 --- a/mk/cfg/x86_64-pc-windows-msvc.mk +++ b/mk/cfg/x86_64-pc-windows-msvc.mk @@ -9,8 +9,8 @@ CFG_STATIC_LIB_NAME_x86_64-pc-windows-msvc=$(1).lib CFG_LIB_GLOB_x86_64-pc-windows-msvc=$(1)-*.dll CFG_LIB_DSYM_GLOB_x86_64-pc-windows-msvc=$(1)-*.dylib.dSYM CFG_JEMALLOC_CFLAGS_x86_64-pc-windows-msvc := -CFG_GCCISH_CFLAGS_x86_64-pc-windows-msvc := -CFG_GCCISH_CXXFLAGS_x86_64-pc-windows-msvc := +CFG_GCCISH_CFLAGS_x86_64-pc-windows-msvc := -MD +CFG_GCCISH_CXXFLAGS_x86_64-pc-windows-msvc := -MD CFG_GCCISH_LINK_FLAGS_x86_64-pc-windows-msvc := CFG_GCCISH_DEF_FLAG_x86_64-pc-windows-msvc := CFG_LLC_FLAGS_x86_64-pc-windows-msvc := From 0d033dd7c259bb52d6fdd01f08c1762db17ea217 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Tue, 9 Jun 2015 00:00:20 +0200 Subject: [PATCH 02/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 d56ecb360cfed..154bb300f61a7 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 03/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 775a6fbd29358..b27db2ab7bea8 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 04/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 580d970af0c3d..00932712a07a4 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 05/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 9c47d7f217aac..853d12172af5e 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 06/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 f309dd0fad6d9..83461feba40d2 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 07/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 9ede835e521c9..8077f04ed6084 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 08/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 a18d9bb442dd2..b24d50c890da4 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 09/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 93df0f19e8eeb..0f356d75abc86 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 10/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 1f694f71a883f..1afa622db7dd3 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 {