From e5a846e90e3a5a73a33b2a587eb8c0f6534c1787 Mon Sep 17 00:00:00 2001 From: Lawrence Woodman Date: Sun, 3 Jan 2016 08:15:24 +0000 Subject: [PATCH 1/9] Correct formatting use of tab instead of spaces --- src/doc/book/error-handling.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/book/error-handling.md b/src/doc/book/error-handling.md index 3479230f77468..0bf99e98c1d26 100644 --- a/src/doc/book/error-handling.md +++ b/src/doc/book/error-handling.md @@ -1573,11 +1573,11 @@ fn main() { let matches = match opts.parse(&args[1..]) { Ok(m) => { m } - Err(e) => { panic!(e.to_string()) } + Err(e) => { panic!(e.to_string()) } }; if matches.opt_present("h") { print_usage(&program, opts); - return; + return; } let data_path = args[1].clone(); let city = args[2].clone(); From ff3ebfa7b9ba4223449cbe3fd2eba4e339aace5c Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 4 Jan 2016 13:03:29 -0500 Subject: [PATCH 2/9] Mention that Sync/Send are automatically derived Fixes #28581 --- src/libcore/marker.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs index b584e59a825ff..65ddae51b98f6 100644 --- a/src/libcore/marker.rs +++ b/src/libcore/marker.rs @@ -24,6 +24,8 @@ use hash::Hash; use hash::Hasher; /// Types that can be transferred across thread boundaries. +/// +/// This trait is automatically derived when the compiler determines it's appropriate. #[stable(feature = "rust1", since = "1.0.0")] #[lang = "send"] #[rustc_on_unimplemented = "`{Self}` cannot be sent between threads safely"] @@ -219,6 +221,8 @@ pub trait Copy : Clone { /// wrapper around the value(s) which can be mutated when behind a `&` /// reference; not doing this is undefined behavior (for example, /// `transmute`-ing from `&T` to `&mut T` is invalid). +/// +/// This trait is automatically derived when the compiler determines it's appropriate. #[stable(feature = "rust1", since = "1.0.0")] #[lang = "sync"] #[rustc_on_unimplemented = "`{Self}` cannot be shared between threads safely"] From 723ead6c9cbe28806f97f43ebfc6df95e758734a Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 4 Jan 2016 12:44:54 -0500 Subject: [PATCH 3/9] Mention that structs can contain &mut Ts Fixes #30254 --- src/doc/book/structs.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/doc/book/structs.md b/src/doc/book/structs.md index 1d70ee2786919..75d0093b1476a 100644 --- a/src/doc/book/structs.md +++ b/src/doc/book/structs.md @@ -88,6 +88,35 @@ fn main() { } ``` +Your structure can still contain `&mut` pointers, which will let +you do some kinds of mutation: + +```rust +struct Point { + x: i32, + y: i32, +} + +struct PointRef<'a> { + x: &'a mut i32, + y: &'a mut i32, +} + +fn main() { + let mut point = Point { x: 0, y: 0 }; + + { + let r = PointRef { x: &mut point.x, y: &mut point.y }; + + *r.x = 5; + *r.y = 6; + } + + assert_eq!(5, point.x); + assert_eq!(6, point.y); +} +``` + # Update syntax A `struct` can include `..` to indicate that you want to use a copy of some From cd4bf34659ca6b94749140b707755d068e837bdb Mon Sep 17 00:00:00 2001 From: Matt Kraai Date: Tue, 5 Jan 2016 07:40:40 -0800 Subject: [PATCH 4/9] Fix the spelling of "hexadecimal" --- src/libcore/char.rs | 2 +- src/librustc_unicode/char.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libcore/char.rs b/src/libcore/char.rs index 43a1bf6e500c0..0fc154a0cd591 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -181,7 +181,7 @@ pub unsafe fn from_u32_unchecked(i: u32) -> char { /// /// A 'radix' here is sometimes also called a 'base'. A radix of two /// indicates a binary number, a radix of ten, decimal, and a radix of -/// sixteen, hexicdecimal, to give some common values. Arbitrary +/// sixteen, hexadecimal, to give some common values. Arbitrary /// radicum are supported. /// /// `from_digit()` will return `None` if the input is not a digit in diff --git a/src/librustc_unicode/char.rs b/src/librustc_unicode/char.rs index 455e2feee4c2f..66f8068eae657 100644 --- a/src/librustc_unicode/char.rs +++ b/src/librustc_unicode/char.rs @@ -126,7 +126,7 @@ impl char { /// /// A 'radix' here is sometimes also called a 'base'. A radix of two /// indicates a binary number, a radix of ten, decimal, and a radix of - /// sixteen, hexicdecimal, to give some common values. Arbitrary + /// sixteen, hexadecimal, to give some common values. Arbitrary /// radicum are supported. /// /// Compared to `is_numeric()`, this function only recognizes the characters @@ -185,7 +185,7 @@ impl char { /// /// A 'radix' here is sometimes also called a 'base'. A radix of two /// indicates a binary number, a radix of ten, decimal, and a radix of - /// sixteen, hexicdecimal, to give some common values. Arbitrary + /// sixteen, hexadecimal, to give some common values. Arbitrary /// radicum are supported. /// /// 'Digit' is defined to be only the following characters: From 011a23e8bce5b3669ae7f23a9838687903fb3b86 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 4 Jan 2016 12:33:43 -0500 Subject: [PATCH 5/9] Update MinGW details in the README Fixes #29649 --- README.md | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 6e5e1ca0c3282..7558065831ace 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,16 @@ Read ["Installing Rust"] from [The Book]. ### Building on Windows +There are two prominent ABIs in use on Windows: the native (MSVC) ABI used by +Visual Studio, and the GNU ABI used by the GCC toolchain. Which version of Rust +you need depends largely on what C/C++ libraries you want to interoperate with: +for interop with software produced by Visual Studio use the MSVC build of Rust; +for interop with GNU software built using the MinGW/MSYS2 toolchain use the GNU +build. + + +#### MinGW + [MSYS2](http://msys2.github.io/) can be used to easily build Rust on Windows: 1. Grab the latest MSYS2 installer and go through the installer. @@ -63,12 +73,15 @@ Read ["Installing Rust"] from [The Book]. ```sh # Update package mirrors (may be needed if you have a fresh install of MSYS2) $ pacman -Sy pacman-mirrors + ``` - # Choose one based on platform: - # *** see the note below *** - $ pacman -S mingw-w64-i686-toolchain - $ pacman -S mingw-w64-x86_64-toolchain +Download [MinGW from +here](http://mingw-w64.org/doku.php/download/mingw-builds), and choose the +`threads=win32,exceptions=dwarf/seh` flavor when installing. After installing, +add its `bin` directory to your `PATH`. This is due to #28260, in the future, +installing from pacman should be just fine. + ``` # Make git available in MSYS2 (if not already available on path) $ pacman -S git @@ -84,16 +97,19 @@ Read ["Installing Rust"] from [The Book]. $ ./configure $ make && make install ``` -> ***Note:*** gcc versions >= 5 currently have issues building LLVM on Windows -> resulting in a segmentation fault when building Rust. In order to avoid this -> it may be necessary to obtain an earlier version of gcc such as 4.9.x. -> Msys's `pacman` will install the latest version, so for the time being it is -> recommended to skip gcc toolchain installation step above and use [Mingw-Builds] -> project's installer instead. Be sure to add gcc `bin` directory to the path -> before running `configure`. -> For more information on this see issue #28260. - -[Mingw-Builds]: http://sourceforge.net/projects/mingw-w64/ + +#### MSVC + +MSVC builds of Rust additionally require an installation of Visual Studio 2013 +(or later) so `rustc` can use its linker. Make sure to check the “C++ tools” +option. In addition, `cmake` needs to be installed to build LLVM. + +With these dependencies installed, the build takes two steps: + +```sh +$ ./configure +$ make && make install +``` ## Building Documentation From 7d6d39bcd948d219f6c26ffb0c2a1ea1f498b65c Mon Sep 17 00:00:00 2001 From: BChip Date: Tue, 5 Jan 2016 15:32:54 -0500 Subject: [PATCH 6/9] Clarify What LIFO Is Declare what LIFO stands for --- src/doc/book/the-stack-and-the-heap.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/book/the-stack-and-the-heap.md b/src/doc/book/the-stack-and-the-heap.md index 63b73a7fc31fc..bc40eeb8dccfb 100644 --- a/src/doc/book/the-stack-and-the-heap.md +++ b/src/doc/book/the-stack-and-the-heap.md @@ -539,7 +539,7 @@ instead. # Which to use? So if the stack is faster and easier to manage, why do we need the heap? A big -reason is that Stack-allocation alone means you only have LIFO semantics for +reason is that Stack-allocation alone means you only have 'Last In First Out (LIFO)' semantics for reclaiming storage. Heap-allocation is strictly more general, allowing storage to be taken from and returned to the pool in arbitrary order, but at a complexity cost. From ce6baa77fe0fb53166f91d38e5187618af9b164c Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Wed, 6 Jan 2016 00:01:59 +0100 Subject: [PATCH 7/9] Clarify how Rust treats backslashes at end of line in string literals Rust differs in that behavior from C: In C, the newline escapes are resolved before anything else, and in Rust this depends on whether the backslash is escaped itself. A difference can be observed in the following two programs: ```c #include int main() { printf("\\ n\n"); return 0; } ``` ```rust fn main() { println!("\\ n"); } ``` The first program prints two newlines, the second one prints a backslash, a newline, the latin character n and a final newline. --- src/doc/reference.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index e7cc1436824e4..5f71ee4437958 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -208,10 +208,10 @@ A _string literal_ is a sequence of any Unicode characters enclosed within two which must be _escaped_ by a preceding `U+005C` character (`\`). 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: +themselves (i.e. no translation), but as a special exception, when an unescaped +`U+005C` character (`\`) occurs immediately before the newline (`U+000A`), 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 4ea84fc1844625eb8049d081620aac53009bce4b Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Wed, 6 Jan 2016 12:28:34 +1100 Subject: [PATCH 8/9] Remove irrelevant comment The fundamental problem of duplication was fixed in https://github.com/rust-lang/rust/pull/10891, but the comment was preserved. Closes https://github.com/rust-lang/rust/issues/9762. --- src/libsyntax/parse/token.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index b942954c1874a..242626154fc8c 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -495,9 +495,6 @@ macro_rules! declare_special_idents_and_keywords {( } fn mk_fresh_ident_interner() -> IdentInterner { - // The indices here must correspond to the numbers in - // special_idents, in Keyword to_name(), and in static - // constants below. let mut init_vec = Vec::new(); $(init_vec.push($si_str);)* $(init_vec.push($sk_str);)* From eb30c661c0f35e44c456e50c2655a4fcdb323f66 Mon Sep 17 00:00:00 2001 From: jonastepe Date: Wed, 6 Jan 2016 12:13:47 +0100 Subject: [PATCH 9/9] heap::deallocate expects a *mut u8 but here a *mut T is given. The final code is correct, the example here would not compile without the cast. I used *mut _ instead of *mut u8 to be consistent with the final code. --- src/doc/nomicon/vec-dealloc.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/nomicon/vec-dealloc.md b/src/doc/nomicon/vec-dealloc.md index b767caa491236..706fe680e0066 100644 --- a/src/doc/nomicon/vec-dealloc.md +++ b/src/doc/nomicon/vec-dealloc.md @@ -21,7 +21,7 @@ impl Drop for Vec { let elem_size = mem::size_of::(); let num_bytes = elem_size * self.cap; unsafe { - heap::deallocate(*self.ptr, num_bytes, align); + heap::deallocate(*self.ptr as *mut _, num_bytes, align); } } }