From bc3c41be9f70f7c289886563974714c9c15429a7 Mon Sep 17 00:00:00 2001 From: Jonathan Hansford Date: Thu, 30 Jul 2015 09:20:13 +0100 Subject: [PATCH 01/11] Clarifications for Hello, Cargo! Just a few minor changes to clarify a few things for someone new to Rust and Cargo. --- src/doc/trpl/hello-cargo.md | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/doc/trpl/hello-cargo.md b/src/doc/trpl/hello-cargo.md index 8e479977887..273ea44c495 100644 --- a/src/doc/trpl/hello-cargo.md +++ b/src/doc/trpl/hello-cargo.md @@ -23,20 +23,21 @@ README][cargoreadme] for specific instructions about installing it. Let’s convert Hello World to Cargo. -To Cargo-ify our project, we need to do two things: Make a `Cargo.toml` -configuration file, and put our source file in the right place. Let's -do that part first: +To Cargo-ify our project, we need to do three things: Make a `Cargo.toml` +configuration file, put our source file in the right place, and get rid of the +old `main.exe`. Let's do that part first: ```bash $ mkdir src $ mv main.rs src/main.rs +$ rm main.exe ``` -Note that since we're creating an executable, we used `main.rs`. If we -want to make a library instead, we should use `lib.rs`. This convention is required -for Cargo to successfully compile our projects, but it can be overridden if we wish. -Custom file locations for the entry point can be specified -with a [`[lib]` or `[[bin]]`][crates-custom] key in the TOML file. +Note that since we're creating an executable, we retain `main.rs` as the source +filename. If we want to make a library instead, we should use `lib.rs`. This +convention is required for Cargo to successfully compile our projects, but it +can be overridden if we wish. Custom file locations for the entry point can be +specified with a [`[lib]` or `[[bin]]`][crates-custom] key in the TOML file. [crates-custom]: http://doc.crates.io/manifest.html#configuring-a-target @@ -63,8 +64,8 @@ version = "0.0.1" authors = [ "Your name " ] ``` -This file is in the [TOML][toml] format. TOML is similar to INI, but has some -extra goodies. According to the TOML docs, +This file is in the [TOML][toml] format. TOML is similar to INI, but has some +extra goodies. According to the TOML docs, > TOML aims to be a minimal configuration file format that's easy to read due > to obvious semantics. TOML is designed to map unambiguously to a hash table. @@ -73,7 +74,8 @@ extra goodies. According to the TOML docs, [toml]: https://github.com/toml-lang/toml -Once you have this file in place, we should be ready to build! To do so, run: +Once you have this file in place in your project's root directory, we should be +ready to build! To do so, run: ```bash $ cargo build From 1d3818ab7caa11d0244ce87ac09250a49db6392d Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Thu, 30 Jul 2015 10:45:00 +0200 Subject: [PATCH 02/11] doc: prelude nits --- src/libstd/prelude/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libstd/prelude/mod.rs b/src/libstd/prelude/mod.rs index 275f415c6fc..4597db41e90 100644 --- a/src/libstd/prelude/mod.rs +++ b/src/libstd/prelude/mod.rs @@ -11,8 +11,8 @@ //! The Rust Prelude //! //! Because `std` is required by most serious Rust software, it is -//! imported at the topmost level of every crate by default, as if the -//! first line of each crate was +//! imported at the topmost level of every crate by default, as if +//! each crate contains the following: //! //! ```ignore //! extern crate std; @@ -23,7 +23,7 @@ //! etc. //! //! Additionally, `std` contains a versioned *prelude* that reexports many of the -//! most common traits, types and functions. *The contents of the prelude are +//! most common traits, types, and functions. *The contents of the prelude are //! imported into every module by default*. Implicitly, all modules behave as if //! they contained the following [`use` statement][book-use]: //! From c2b564557d3c2c4ff8ba530a533da643c29694f6 Mon Sep 17 00:00:00 2001 From: Jonathan Hansford Date: Thu, 30 Jul 2015 11:58:13 +0100 Subject: [PATCH 03/11] By default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guessing Game states that "Rust only imports a few things into every program, the ‘prelude’". That isn't strictly true. That is all it imports by default and the change clarifies that point. --- src/doc/trpl/guessing-game.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/guessing-game.md b/src/doc/trpl/guessing-game.md index 1784c253f7f..b9063ffaa34 100644 --- a/src/doc/trpl/guessing-game.md +++ b/src/doc/trpl/guessing-game.md @@ -98,8 +98,8 @@ use std::io; We’ll need to take user input, and then print the result as output. As such, we need the `io` library from the standard library. Rust only imports a few things -into every program, [the ‘prelude’][prelude]. If it’s not in the prelude, -you’ll have to `use` it directly. +by default into every program, [the ‘prelude’][prelude]. If it’s not in the +prelude, you’ll have to `use` it directly. [prelude]: ../std/prelude/index.html From 412366fe36ea5c44803c3a9bf9943684a5068d63 Mon Sep 17 00:00:00 2001 From: Kelvin Ly Date: Fri, 31 Jul 2015 08:22:07 -0400 Subject: [PATCH 04/11] Add diagnostic messages for E0074-E0077 --- src/librustc_typeck/diagnostics.rs | 61 ++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index d94870c68bd..4526ee98962 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -826,6 +826,63 @@ struct Foo { x: Option> } Now it's possible to create at least one instance of `Foo`: `Foo { x: None }`. "##, +E0074: r##" +When using the `#[simd]` attribute on a tuple struct, the components of the +tuple struct must all be of a concrete, nongeneric type so the compiler can +reason about how to use SIMD with them. This error will occur if the types +are generic. + +``` +#[simd] +struct Bad(T, T, T); // This will cause an error + +#[simd] +struct Good(u32, u32, u32); // This will not +``` +"##, + +E0075: r##" +The `#[simd]` attribute can only be applied to non empty tuple structs, because +it doesn't make sense to try to use SIMD operations when there are no values to +operate on. + +``` +#[simd] +struct Bad; // This will cause an error + +#[simd] +struct Good(u32); // This will not +``` +"##, + +E0076: r##" +When using the `#[simd]` attribute to automatically use SIMD operations in tuple +struct, the types in the struct must all be of the same type, or the compiler +will trigger this error. + +``` +#[simd] +struct Bad(u16, u32, u32); // This will cause an error + +#[simd] +struct Good(u32, u32, u32); // This will not +``` + +"##, + +E0077: r##" +When using the `#[simd]` attribute on a tuple struct, the elements in the tuple +must be machine types so SIMD operations can be applied to them. + +``` +#[simd] +struct Bad(String); // This will cause an error + +#[simd] +struct Good(u32, u32, u32); // This will not +``` +"##, + E0081: r##" Enum discriminants are used to differentiate enum variants stored in memory. This error indicates that the same value was used for two or more variants, @@ -2299,10 +2356,6 @@ https://doc.rust-lang.org/std/marker/struct.PhantomData.html register_diagnostics! { E0068, - E0074, - E0075, - E0076, - E0077, E0085, E0086, E0090, From 91972ba5a614d0d6440ef5440049e3c8e576119d Mon Sep 17 00:00:00 2001 From: Jan Likar Date: Sat, 1 Aug 2015 22:04:23 +0200 Subject: [PATCH 05/11] Fix "Ignoring variants" in "Patterns" chapter - Fix #26968 by noting the difference between ".." and "_" more explicitly - Change one of the examples to show the match-all behaviour of ".." - Merge "Ignoring variants" and "Ignoring bindings" sections into the latter --- src/doc/trpl/patterns.md | 89 +++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/src/doc/trpl/patterns.md b/src/doc/trpl/patterns.md index 9603eec7aca..1abd4ca6c21 100644 --- a/src/doc/trpl/patterns.md +++ b/src/doc/trpl/patterns.md @@ -112,26 +112,55 @@ match x { } ``` -# Ignoring variants +# Ignoring bindings -If you’re matching on an enum which has variants, you can use `..` to -ignore the value and type in the variant: +You can use `_` in a pattern to disregard the type and value. +For example, here’s a `match` against a `Result`: ```rust -enum OptionalInt { - Value(i32), - Missing, -} - -let x = OptionalInt::Value(5); - -match x { - OptionalInt::Value(..) => println!("Got an int!"), - OptionalInt::Missing => println!("No such luck."), +# let some_value: Result = Err("There was an error"); +match some_value { + Ok(value) => println!("got a value: {}", value), + Err(_) => println!("an error occurred"), } ``` -This prints `Got an int!`. +In the first arm, we bind the value inside the `Ok` variant to `value`. But +in the `Err` arm, we use `_` to disregard the specific error, and just print +a general error message. + +`_` is valid in any pattern that creates a binding. This can be useful to +ignore parts of a larger structure: + +```rust +fn coordinate() -> (i32, i32, i32) { + // generate and return some sort of triple tuple +# (1, 2, 3) +} + +let (x, _, z) = coordinate(); +``` + +Here, we bind the first and last element of the tuple to `x` and `z`, but +ignore the middle element. + +Similarly, you can use `..` in a pattern to disregard multiple values. + +```rust +enum OptionalTuple { + Value(i32, i32, i32), + Missing, +} + +let x = OptionalTuple::Value(5, -2, 3); + +match x { + OptionalTuple::Value(..) => println!("Got a tuple!"), + OptionalTuple::Missing => println!("No such luck."), +} +``` + +This prints `Got a tuple!`. # Guards @@ -282,38 +311,6 @@ This ‘destructuring’ behavior works on any compound data type, like [tuples]: primitive-types.html#tuples [enums]: enums.html -# Ignoring bindings - -You can use `_` in a pattern to disregard the value. For example, here’s a -`match` against a `Result`: - -```rust -# let some_value: Result = Err("There was an error"); -match some_value { - Ok(value) => println!("got a value: {}", value), - Err(_) => println!("an error occurred"), -} -``` - -In the first arm, we bind the value inside the `Ok` variant to `value`. But -in the `Err` arm, we use `_` to disregard the specific error, and just print -a general error message. - -`_` is valid in any pattern that creates a binding. This can be useful to -ignore parts of a larger structure: - -```rust -fn coordinate() -> (i32, i32, i32) { - // generate and return some sort of triple tuple -# (1, 2, 3) -} - -let (x, _, z) = coordinate(); -``` - -Here, we bind the first and last element of the tuple to `x` and `z`, but -ignore the middle element. - # Mix and Match Whew! That’s a lot of different ways to match things, and they can all be From d6f713be3fbdcfe3508fd8801a0e2eda0c076307 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 3 Aug 2015 10:43:13 +0200 Subject: [PATCH 06/11] Improve E0423 error message --- src/librustc_resolve/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index fa9c7a2038c..85c2f0cbe05 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -313,8 +313,8 @@ fn resolve_error<'b, 'a:'b, 'tcx:'a>(resolver: &'b Resolver<'a, 'tcx>, span: syn }, ResolutionError::StructVariantUsedAsFunction(path_name) => { span_err!(resolver.session, span, E0423, - "`{}` is a struct variant name, but \ - this expression \ + "`{}` is the name of a struct or struct variant, \ + but this expression \ uses it like a function name", path_name); }, From d9b18822489f5734eed9698beef3b0076d0ab9b3 Mon Sep 17 00:00:00 2001 From: Jonathan Hansford Date: Mon, 3 Aug 2015 10:22:03 +0100 Subject: [PATCH 07/11] Updated in response to review --- src/doc/trpl/hello-cargo.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/doc/trpl/hello-cargo.md b/src/doc/trpl/hello-cargo.md index 273ea44c495..7df04792ec8 100644 --- a/src/doc/trpl/hello-cargo.md +++ b/src/doc/trpl/hello-cargo.md @@ -8,13 +8,13 @@ so it is assumed that Rust projects will use Cargo from the beginning. [cratesio]: http://doc.crates.io Cargo manages three things: building your code, downloading the dependencies -your code needs, and building those dependencies. At first, your -program doesn’t have any dependencies, so we’ll only be using the first part of -its functionality. Eventually, we’ll add more. Since we started off by using -Cargo, it'll be easy to add later. +your code needs, and building those dependencies. At first, your program doesn’t +have any dependencies, so we’ll only be using the first part of its +functionality. Eventually, we’ll add more. Since we started off by using Cargo, +it'll be easy to add later. -If you installed Rust via the official installers you will also have Cargo. If -you installed Rust some other way, you may want to [check the Cargo +If we installed Rust via the official installers we will also have Cargo. If we +installed Rust some other way, we may want to [check the Cargo README][cargoreadme] for specific instructions about installing it. [cargoreadme]: https://github.com/rust-lang/cargo#installing-cargo-from-nightlies @@ -25,18 +25,18 @@ Let’s convert Hello World to Cargo. To Cargo-ify our project, we need to do three things: Make a `Cargo.toml` configuration file, put our source file in the right place, and get rid of the -old `main.exe`. Let's do that part first: +old executable (`main.exe` on Windows, `main` everywhere else). Let's do that part first: ```bash $ mkdir src $ mv main.rs src/main.rs -$ rm main.exe +$ rm main # or main.exe on Windows ``` Note that since we're creating an executable, we retain `main.rs` as the source filename. If we want to make a library instead, we should use `lib.rs`. This convention is required for Cargo to successfully compile our projects, but it -can be overridden if we wish. Custom file locations for the entry point can be +can be overridden if we wish. Custom file locations for the entry point can be specified with a [`[lib]` or `[[bin]]`][crates-custom] key in the TOML file. [crates-custom]: http://doc.crates.io/manifest.html#configuring-a-target From 549de0d47a7876e7ff4e2c664e816a9fbe758073 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 3 Aug 2015 16:50:18 +0200 Subject: [PATCH 08/11] Update error comment --- src/test/compile-fail/issue-6702.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/compile-fail/issue-6702.rs b/src/test/compile-fail/issue-6702.rs index bfda113ae8b..66ed817ffa8 100644 --- a/src/test/compile-fail/issue-6702.rs +++ b/src/test/compile-fail/issue-6702.rs @@ -14,6 +14,6 @@ struct Monster { fn main() { - let _m = Monster(); //~ ERROR `Monster` is a struct variant name, but + let _m = Monster(); //~ ERROR `Monster` is the name of a struct or //~^ HELP did you mean to write: `Monster { /* fields */ }`? } From c5d877977a3d89ad9763b734405be41e3a041dcc Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Mon, 3 Aug 2015 21:52:20 +0300 Subject: [PATCH 09/11] Post merge changes to #27488 --- src/libcore/mem.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 3b321d43b3d..7e63c8d71f9 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -322,20 +322,16 @@ pub unsafe fn dropped() -> T { /// println!("{:?}", &data[0]); /// ``` /// -/// Hopefully this example emphasizes to you exactly how delicate -/// and dangerous doing this is. Note that the `vec!` macro -/// *does* let you initialize every element with a value that -/// is only `Clone`, so the following is equivalent and vastly -/// less dangerous, as long as you can live with an extra heap +/// This example emphasizes exactly how delicate and dangerous doing this is. +/// Note that the `vec!` macro *does* let you initialize every element with a +/// value that is only `Clone`, so the following is semantically equivalent and +/// vastly less dangerous, as long as you can live with an extra heap /// allocation: /// /// ``` /// let data: Vec> = vec![Vec::new(); 1000]; /// println!("{:?}", &data[0]); /// ``` -/// -/// For large arrays this is probably advisable -/// anyway to avoid blowing the stack. #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn uninitialized() -> T { From d7b93216cdeb477e1af813f898096af867550338 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 3 Aug 2015 16:19:21 -0400 Subject: [PATCH 10/11] small fix in RELEASES this grammar isn't correct --- RELEASES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index 0c495595511..1dfd2186e13 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -79,7 +79,7 @@ Libraries are used by code generators to emit implementations of [`Debug`]. * `str` has new [`to_uppercase`][strup] and [`to_lowercase`][strlow] methods that convert case, following Unicode case mapping. -* It is now easier to handle to poisoned locks. The [`PoisonError`] +* It is now easier to handle poisoned locks. The [`PoisonError`] type, returned by failing lock operations, exposes `into_inner`, `get_ref`, and `get_mut`, which all give access to the inner lock guard, and allow the poisoned lock to continue to operate. The From c54df0e4541f66d43109c844782c43a2bd24d97d Mon Sep 17 00:00:00 2001 From: Jonathan Hansford Date: Mon, 3 Aug 2015 21:37:15 +0100 Subject: [PATCH 11/11] required -> used; you -> we --- src/doc/trpl/hello-cargo.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/doc/trpl/hello-cargo.md b/src/doc/trpl/hello-cargo.md index 7df04792ec8..4bd7de23f0c 100644 --- a/src/doc/trpl/hello-cargo.md +++ b/src/doc/trpl/hello-cargo.md @@ -35,8 +35,8 @@ $ rm main # or main.exe on Windows Note that since we're creating an executable, we retain `main.rs` as the source filename. If we want to make a library instead, we should use `lib.rs`. This -convention is required for Cargo to successfully compile our projects, but it -can be overridden if we wish. Custom file locations for the entry point can be +convention is used by Cargo to successfully compile our projects, but it can be +overridden if we wish. Custom file locations for the entry point can be specified with a [`[lib]` or `[[bin]]`][crates-custom] key in the TOML file. [crates-custom]: http://doc.crates.io/manifest.html#configuring-a-target @@ -74,7 +74,7 @@ extra goodies. According to the TOML docs, [toml]: https://github.com/toml-lang/toml -Once you have this file in place in your project's root directory, we should be +Once we have this file in place in our project's root directory, we should be ready to build! To do so, run: ```bash