From 93f2a54609540859d26a30eb833388b20621182b Mon Sep 17 00:00:00 2001 From: srinivasreddy Date: Thu, 10 Mar 2016 21:48:15 +0530 Subject: [PATCH 1/9] first round of removal of integer suffixes --- src/liballoc/arc.rs | 8 ++++---- src/liballoc/rc.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index b5d7279edb0..1dac7dca348 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -107,7 +107,7 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize; /// use std::thread; /// /// fn main() { -/// let numbers: Vec<_> = (0..100u32).collect(); +/// let numbers: Vec<_> = (0..100).collect(); /// let shared_numbers = Arc::new(numbers); /// /// for _ in 0..10 { @@ -1118,7 +1118,7 @@ mod tests { #[test] fn test_strong_count() { - let a = Arc::new(0u32); + let a = Arc::new(0); assert!(Arc::strong_count(&a) == 1); let w = Arc::downgrade(&a); assert!(Arc::strong_count(&a) == 1); @@ -1135,7 +1135,7 @@ mod tests { #[test] fn test_weak_count() { - let a = Arc::new(0u32); + let a = Arc::new(0); assert!(Arc::strong_count(&a) == 1); assert!(Arc::weak_count(&a) == 0); let w = Arc::downgrade(&a); @@ -1161,7 +1161,7 @@ mod tests { #[test] fn show_arc() { - let a = Arc::new(5u32); + let a = Arc::new(5); assert_eq!(format!("{:?}", a), "5"); } diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index dc283f5acdf..da803f57a59 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -1014,7 +1014,7 @@ mod tests { #[test] fn test_strong_count() { - let a = Rc::new(0u32); + let a = Rc::new(0); assert!(Rc::strong_count(&a) == 1); let w = Rc::downgrade(&a); assert!(Rc::strong_count(&a) == 1); @@ -1031,7 +1031,7 @@ mod tests { #[test] fn test_weak_count() { - let a = Rc::new(0u32); + let a = Rc::new(0); assert!(Rc::strong_count(&a) == 1); assert!(Rc::weak_count(&a) == 0); let w = Rc::downgrade(&a); From 91a42bedcf251609333acf65761027a4280ba4ca Mon Sep 17 00:00:00 2001 From: srinivasreddy Date: Thu, 10 Mar 2016 22:03:12 +0530 Subject: [PATCH 2/9] removed integer suffixes in libcollections and libcollectionstest --- src/libcollections/linked_list.rs | 16 ++++++++-------- src/libcollectionstest/slice.rs | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libcollections/linked_list.rs b/src/libcollections/linked_list.rs index cb669a9bf9e..f4a67daf974 100644 --- a/src/libcollections/linked_list.rs +++ b/src/libcollections/linked_list.rs @@ -1305,10 +1305,10 @@ mod tests { // // https://github.com/rust-lang/rust/issues/26021 let mut v1 = LinkedList::new(); - v1.push_front(1u8); - v1.push_front(1u8); - v1.push_front(1u8); - v1.push_front(1u8); + v1.push_front(1); + v1.push_front(1); + v1.push_front(1); + v1.push_front(1); let _ = v1.split_off(3); // Dropping this now should not cause laundry consumption assert_eq!(v1.len(), 3); @@ -1319,10 +1319,10 @@ mod tests { #[test] fn test_split_off() { let mut v1 = LinkedList::new(); - v1.push_front(1u8); - v1.push_front(1u8); - v1.push_front(1u8); - v1.push_front(1u8); + v1.push_front(1); + v1.push_front(1); + v1.push_front(1); + v1.push_front(1); // test all splits for ix in 0..1 + v1.len() { diff --git a/src/libcollectionstest/slice.rs b/src/libcollectionstest/slice.rs index f3bb58ba45b..f286fb1e274 100644 --- a/src/libcollectionstest/slice.rs +++ b/src/libcollectionstest/slice.rs @@ -267,9 +267,9 @@ fn test_swap_remove_fail() { fn test_swap_remove_noncopyable() { // Tests that we don't accidentally run destructors twice. let mut v: Vec> = Vec::new(); - v.push(box 0u8); - v.push(box 0u8); - v.push(box 0u8); + v.push(box 0); + v.push(box 0); + v.push(box 0); let mut _e = v.swap_remove(0); assert_eq!(v.len(), 2); _e = v.swap_remove(1); @@ -896,7 +896,7 @@ fn test_overflow_does_not_cause_segfault_managed() { #[test] fn test_mut_split_at() { - let mut values = [1u8,2,3,4,5]; + let mut values = [1,2,3,4,5]; { let (left, right) = values.split_at_mut(2); { From ccafdae9a11925cbc79c6ea4446688ef71bae1a1 Mon Sep 17 00:00:00 2001 From: Florian Berger Date: Sun, 13 Mar 2016 21:57:24 +0200 Subject: [PATCH 3/9] Remove trailing whitespace at the end of lines --- CONTRIBUTING.md | 4 ++-- src/doc/book/casting-between-types.md | 14 +++++++------- src/doc/book/const-and-static.md | 2 +- src/doc/book/match.md | 8 ++++---- src/doc/book/ownership.md | 6 +++--- src/doc/book/primitive-types.md | 2 +- src/doc/book/vectors.md | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 609bf03fb6c..8f721709b9f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -132,8 +132,8 @@ Some common make targets are: - `make check-stage1-std NO_REBUILD=1` - test the standard library without rebuilding the entire compiler - `make check TESTNAME=` - Run a matching set of tests. - - `TESTNAME` should be a substring of the tests to match against e.g. it could - be the fully qualified test name, or just a part of it. + - `TESTNAME` should be a substring of the tests to match against e.g. it could + be the fully qualified test name, or just a part of it. `TESTNAME=collections::hash::map::test_map::test_capacity_not_less_than_len` or `TESTNAME=test_capacity_not_less_than_len`. - `make check-stage1-rpass TESTNAME=` - Run a single diff --git a/src/doc/book/casting-between-types.md b/src/doc/book/casting-between-types.md index 5cafe169369..7d03d2991ab 100644 --- a/src/doc/book/casting-between-types.md +++ b/src/doc/book/casting-between-types.md @@ -17,12 +17,12 @@ function result. The most common case of coercion is removing mutability from a reference: * `&mut T` to `&T` - + An analogous conversion is to remove mutability from a [raw pointer](raw-pointers.md): * `*mut T` to `*const T` - + References can also be coerced to raw pointers: * `&T` to `*const T` @@ -32,7 +32,7 @@ References can also be coerced to raw pointers: Custom coercions may be defined using [`Deref`](deref-coercions.md). Coercion is transitive. - + # `as` The `as` keyword does safe casting: @@ -64,7 +64,7 @@ A cast `e as U` is also valid in any of the following cases: and `U` is an integer type; *enum-cast* * `e` has type `bool` or `char` and `U` is an integer type; *prim-int-cast* * `e` has type `u8` and `U` is `char`; *u8-char-cast* - + For example ```rust @@ -98,9 +98,9 @@ The semantics of numeric casts are: [float-int]: https://github.com/rust-lang/rust/issues/10184 [float-float]: https://github.com/rust-lang/rust/issues/15536 - + ## Pointer casts - + Perhaps surprisingly, it is safe to cast [raw pointers](raw-pointers.md) to and from integers, and to cast between pointers to different types subject to some constraints. It is only unsafe to dereference the pointer: @@ -114,7 +114,7 @@ let b = a as u32; * `e` has type `*T`, `U` has type `*U_0`, and either `U_0: Sized` or `unsize_kind(T) == unsize_kind(U_0)`; a *ptr-ptr-cast* - + * `e` has type `*T` and `U` is a numeric type, while `T: Sized`; *ptr-addr-cast* * `e` is an integer and `U` is `*U_0`, while `U_0: Sized`; *addr-ptr-cast* diff --git a/src/doc/book/const-and-static.md b/src/doc/book/const-and-static.md index b7042854bd2..08ff3894c9d 100644 --- a/src/doc/book/const-and-static.md +++ b/src/doc/book/const-and-static.md @@ -72,7 +72,7 @@ a [`Drop`][drop] implementation. # Initializing Both `const` and `static` have requirements for giving them a value. They must -be given a value that’s a constant expression. In other words, you cannot use +be given a value that’s a constant expression. In other words, you cannot use the result of a function call or anything similarly complex or at runtime. # Which construct should I use? diff --git a/src/doc/book/match.md b/src/doc/book/match.md index 1c327c376e2..d01a20083ef 100644 --- a/src/doc/book/match.md +++ b/src/doc/book/match.md @@ -28,8 +28,8 @@ patterns][patterns] that covers all the patterns that are possible here. [patterns]: patterns.html -One of the many advantages of `match` is it enforces ‘exhaustiveness checking’. -For example if we remove the last arm with the underscore `_`, the compiler will +One of the many advantages of `match` is it enforces ‘exhaustiveness checking’. +For example if we remove the last arm with the underscore `_`, the compiler will give us an error: ```text @@ -58,7 +58,7 @@ let number = match x { }; ``` -Sometimes it’s a nice way of converting something from one type to another; in +Sometimes it’s a nice way of converting something from one type to another; in this example the integers are converted to `String`. # Matching on enums @@ -90,7 +90,7 @@ fn process_message(msg: Message) { Again, the Rust compiler checks exhaustiveness, so it demands that you have a match arm for every variant of the enum. If you leave one off, it -will give you a compile-time error unless you use `_` or provide all possible +will give you a compile-time error unless you use `_` or provide all possible arms. Unlike the previous uses of `match`, you can’t use the normal `if` diff --git a/src/doc/book/ownership.md b/src/doc/book/ownership.md index 7f7f7d4c8eb..f8938be30ed 100644 --- a/src/doc/book/ownership.md +++ b/src/doc/book/ownership.md @@ -124,7 +124,7 @@ special annotation here, it’s the default thing that Rust does. ## The details The reason that we cannot use a binding after we’ve moved it is subtle, but -important. +important. When we write code like this: @@ -148,7 +148,7 @@ The first line allocates memory for the vector object `v` on the stack like it does for `x` above. But in addition to that it also allocates some memory on the [heap][sh] for the actual data (`[1, 2, 3]`). Rust copies the address of this heap allocation to an internal pointer, which is part of the vector -object placed on the stack (let's call it the data pointer). +object placed on the stack (let's call it the data pointer). It is worth pointing out (even at the risk of stating the obvious) that the vector object and its data live in separate memory regions instead of being a @@ -163,7 +163,7 @@ does not create a copy of the heap allocation containing the actual data. Which means that there would be two pointers to the contents of the vector both pointing to the same memory allocation on the heap. It would violate Rust’s safety guarantees by introducing a data race if one could access both -`v` and `v2` at the same time. +`v` and `v2` at the same time. For example if we truncated the vector to just two elements through `v2`: diff --git a/src/doc/book/primitive-types.md b/src/doc/book/primitive-types.md index 8dfbf4ada76..69040931de6 100644 --- a/src/doc/book/primitive-types.md +++ b/src/doc/book/primitive-types.md @@ -164,7 +164,7 @@ copying. For example, you might want to reference only one line of a file read into memory. By nature, a slice is not created directly, but from an existing variable binding. Slices have a defined length, can be mutable or immutable. -Internally, slices are represented as a pointer to the beginning of the data +Internally, slices are represented as a pointer to the beginning of the data and a length. ## Slicing syntax diff --git a/src/doc/book/vectors.md b/src/doc/book/vectors.md index ceb6b3c003e..6ac701e2969 100644 --- a/src/doc/book/vectors.md +++ b/src/doc/book/vectors.md @@ -116,7 +116,7 @@ for i in v { ``` Note: You cannot use the vector again once you have iterated by taking ownership of the vector. -You can iterate the vector multiple times by taking a reference to the vector whilst iterating. +You can iterate the vector multiple times by taking a reference to the vector whilst iterating. For example, the following code does not compile. ```rust,ignore From 311ee0157add2bae24671336fc9da58a3fa798ea Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 25 Mar 2016 01:42:40 +0100 Subject: [PATCH 4/9] Add an example for E0034 --- src/librustc_typeck/diagnostics.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 300868721e3..bef6c1ed43a 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -327,6 +327,30 @@ fn main() { ::foo() } ``` + +One last example: + +``` +trait F { + fn m(&self); +} + +trait G { + fn m(&self); +} + +struct X; + +impl F for X { fn m(&self) { println!("I am F"); } } +impl G for X { fn m(&self) { println!("I am G"); } } + +fn main() { + let f = X; + + F::m(&f); // it displays "I am F" + G::m(&f); // it displays "I am G" +} +``` "##, E0035: r##" From e469c79de810b1e16ddfba4296da49fc077c9938 Mon Sep 17 00:00:00 2001 From: Tang Chenglong Date: Sat, 26 Mar 2016 21:18:08 +0800 Subject: [PATCH 5/9] Docs: a tiny modification --- src/doc/book/closures.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/book/closures.md b/src/doc/book/closures.md index 237545edc05..2afe995aeea 100644 --- a/src/doc/book/closures.md +++ b/src/doc/book/closures.md @@ -502,5 +502,5 @@ assert_eq!(6, answer); ``` By making the inner closure a `move Fn`, we create a new stack frame for our -closure. By `Box`ing it up, we’ve given it a known size, and allowing it to +closure. By `Box`ing it up, we’ve given it a known size, allowing it to escape our stack frame. From 2eb84299ca0a23d48ab5f7e489d72708d99b1a1e Mon Sep 17 00:00:00 2001 From: Andreas Linz Date: Sat, 26 Mar 2016 14:53:27 +0100 Subject: [PATCH 6/9] Fix missing console output in `Barrier` example The `println!` calls in the previous version were never shown (at least not in the playpen) because the main thread is finished before all the spawned child threads were synchronized. This commit adds a join for each thread handle to wait in the main thread until all child threads are finished. --- src/libstd/sync/barrier.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libstd/sync/barrier.rs b/src/libstd/sync/barrier.rs index 4df6ca5f0b8..b543240c15a 100644 --- a/src/libstd/sync/barrier.rs +++ b/src/libstd/sync/barrier.rs @@ -17,16 +17,21 @@ use sync::{Mutex, Condvar}; /// use std::sync::{Arc, Barrier}; /// use std::thread; /// +/// let mut handles = Vec::with_capacity(10); /// let barrier = Arc::new(Barrier::new(10)); /// for _ in 0..10 { /// let c = barrier.clone(); /// // The same messages will be printed together. /// // You will NOT see any interleaving. -/// thread::spawn(move|| { +/// handles.push(thread::spawn(move|| { /// println!("before wait"); /// c.wait(); /// println!("after wait"); -/// }); +/// })); +/// } +/// // Wait for other threads to finish. +/// for handle in handles { +/// handle.join().unwrap(); /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] From bbba872dde00b7947e75c6055dba5c82f2f7978a Mon Sep 17 00:00:00 2001 From: Tang Chenglong Date: Sat, 26 Mar 2016 23:59:16 +0800 Subject: [PATCH 7/9] docs: make some text changes on Section `Macros` (1) In contrast to `that`, `so that` expresses `result` indicated by the sentence, not `reason`; (2) `block` is an expression, and may be have an expression, so I add `optional an expression` to make more precise; (3) When I read here, I was confused with what `the child` referred to. After modification, it would be better. --- src/doc/book/macros.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/doc/book/macros.md b/src/doc/book/macros.md index 188abb316ab..1dbf8b49132 100644 --- a/src/doc/book/macros.md +++ b/src/doc/book/macros.md @@ -337,8 +337,8 @@ fn main() { } ``` -Instead you need to pass the variable name into the invocation, so it’s tagged -with the right syntax context. +Instead you need to pass the variable name into the invocation, so that it’s +tagged with the right syntax context. ```rust macro_rules! foo { @@ -470,7 +470,7 @@ which syntactic form it matches. * `ty`: a type. Examples: `i32`; `Vec<(char, String)>`; `&T`. * `pat`: a pattern. Examples: `Some(t)`; `(17, 'a')`; `_`. * `stmt`: a single statement. Example: `let x = 3`. -* `block`: a brace-delimited sequence of statements. Example: +* `block`: a brace-delimited sequence of statements and optional an expression. Example: `{ log(error, "hi"); return 12; }`. * `item`: an [item][item]. Examples: `fn foo() { }`; `struct Bar;`. * `meta`: a "meta item", as found in attributes. Example: `cfg(target_os = "windows")`. @@ -509,7 +509,7 @@ A macro defined within the body of a single `fn`, or anywhere else not at module scope, is visible only within that item. If a module has the `macro_use` attribute, its macros are also visible in its -parent module after the child’s `mod` item. If the parent also has `macro_use` +parent module after its `mod` item. If the parent also has `macro_use` then the macros will be visible in the grandparent after the parent’s `mod` item, and so forth. From 708c5d09d7a355c506960581e16306c96eb7d019 Mon Sep 17 00:00:00 2001 From: Tang Chenglong Date: Sun, 27 Mar 2016 17:59:33 +0800 Subject: [PATCH 8/9] Update macros.md --- src/doc/book/macros.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/book/macros.md b/src/doc/book/macros.md index 1dbf8b49132..c16e2ea4535 100644 --- a/src/doc/book/macros.md +++ b/src/doc/book/macros.md @@ -470,7 +470,7 @@ which syntactic form it matches. * `ty`: a type. Examples: `i32`; `Vec<(char, String)>`; `&T`. * `pat`: a pattern. Examples: `Some(t)`; `(17, 'a')`; `_`. * `stmt`: a single statement. Example: `let x = 3`. -* `block`: a brace-delimited sequence of statements and optional an expression. Example: +* `block`: a brace-delimited sequence of statements and optionally an expression. Example: `{ log(error, "hi"); return 12; }`. * `item`: an [item][item]. Examples: `fn foo() { }`; `struct Bar;`. * `meta`: a "meta item", as found in attributes. Example: `cfg(target_os = "windows")`. @@ -509,7 +509,7 @@ A macro defined within the body of a single `fn`, or anywhere else not at module scope, is visible only within that item. If a module has the `macro_use` attribute, its macros are also visible in its -parent module after its `mod` item. If the parent also has `macro_use` +parent module after the child’s `mod` item. If the parent also has `macro_use` then the macros will be visible in the grandparent after the parent’s `mod` item, and so forth. From dd08804f0a3ca401a92a96a431ff96cd1b0059db Mon Sep 17 00:00:00 2001 From: Christian Wesselhoeft Date: Sun, 27 Mar 2016 12:15:31 -0600 Subject: [PATCH 9/9] Getting Started: "copy" -> "move" --- src/doc/book/getting-started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/book/getting-started.md b/src/doc/book/getting-started.md index 539fdd32c6b..16c43b5e7a5 100644 --- a/src/doc/book/getting-started.md +++ b/src/doc/book/getting-started.md @@ -417,7 +417,7 @@ first. This leaves the top-level project directory (in this case, to your code. In this way, using Cargo helps you keep your projects nice and tidy. There's a place for everything, and everything is in its place. -Now, copy *main.rs* to the *src* directory, and delete the compiled file you +Now, move *main.rs* into the *src* directory, and delete the compiled file you created with `rustc`. As usual, replace `main` with `main.exe` if you're on Windows.