From 01da14b149ad3cde321d327c31092fd284d7d73e Mon Sep 17 00:00:00 2001 From: Aaklo Xu Date: Fri, 20 May 2016 21:55:19 +0800 Subject: [PATCH 1/8] Fix references links There are Duplicate link references in the article and the format is incorrect. --- src/doc/book/primitive-types.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/doc/book/primitive-types.md b/src/doc/book/primitive-types.md index 2a4b7ba37f25b..330e3bf6a61cb 100644 --- a/src/doc/book/primitive-types.md +++ b/src/doc/book/primitive-types.md @@ -171,12 +171,10 @@ and a length. ## Slicing syntax You can use a combo of `&` and `[]` to create a slice from various things. The -`&` indicates that slices are similar to [references], which we will cover in +`&` indicates that slices are similar to [references][references], which we will cover in detail later in this section. The `[]`s, with a range, let you define the length of the slice: -[references]: references-and-borrowing.html - ```rust let a = [0, 1, 2, 3, 4]; let complete = &a[..]; // A slice containing all of the elements in a @@ -198,7 +196,7 @@ documentation][slice]. Rust’s `str` type is the most primitive string type. As an [unsized type][dst], it’s not very useful by itself, but becomes useful when placed behind a reference, like `&str`. We'll elaborate further when we cover -[Strings][strings] and [references]. +[Strings][strings] and [references][references]. [dst]: unsized-types.html [strings]: strings.html From 4c7b963862edb720c8426e5c536191e4e287f2bd Mon Sep 17 00:00:00 2001 From: Aaklo Xu Date: Sat, 21 May 2016 14:40:57 +0800 Subject: [PATCH 2/8] src/doc: Keep the original style of links --- src/doc/book/primitive-types.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/book/primitive-types.md b/src/doc/book/primitive-types.md index 330e3bf6a61cb..b6a123bb3674c 100644 --- a/src/doc/book/primitive-types.md +++ b/src/doc/book/primitive-types.md @@ -171,7 +171,7 @@ and a length. ## Slicing syntax You can use a combo of `&` and `[]` to create a slice from various things. The -`&` indicates that slices are similar to [references][references], which we will cover in +`&` indicates that slices are similar to [references], which we will cover in detail later in this section. The `[]`s, with a range, let you define the length of the slice: @@ -196,7 +196,7 @@ documentation][slice]. Rust’s `str` type is the most primitive string type. As an [unsized type][dst], it’s not very useful by itself, but becomes useful when placed behind a reference, like `&str`. We'll elaborate further when we cover -[Strings][strings] and [references][references]. +[Strings][strings] and [references]. [dst]: unsized-types.html [strings]: strings.html From 30dd087baafad3a1ff5396e8243ceaf0144bae69 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 22 May 2016 01:13:26 +0200 Subject: [PATCH 3/8] Update repr_simd --- src/librustc_typeck/diagnostics.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 5f2997a86a9f2..002bc5280ad13 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -978,18 +978,18 @@ are generic. This will cause an error: ```compile_fail -#![feature(simd)] +#![feature(repr_simd)] -#[simd] +#[repr(simd)] struct Bad(T, T, T); ``` This will not: ``` -#![feature(simd)] +#![feature(repr_simd)] -#[simd] +#[repr(simd)] struct Good(u32, u32, u32); ``` "##, @@ -1026,18 +1026,18 @@ will trigger this error. This will cause an error: ```compile_fail -#![feature(simd)] +#![feature(repr_simd)] -#[simd] +#[repr(simd)] struct Bad(u16, u32, u32); ``` This will not: ``` -#![feature(simd)] +#![feature(repr_simd)] -#[simd] +#[repr(simd)] struct Good(u32, u32, u32); ``` "##, @@ -1049,18 +1049,18 @@ must be machine types so SIMD operations can be applied to them. This will cause an error: ```compile_fail -#![feature(simd)] +#![feature(repr_simd)] -#[simd] +#[repr(simd)] struct Bad(String); ``` This will not: ``` -#![feature(simd)] +#![feature(repr_simd)] -#[simd] +#[repr(simd)] struct Good(u32, u32, u32); ``` "##, From 62e387102ab4f46e4b72ae9261bb4b65fc32f506 Mon Sep 17 00:00:00 2001 From: ggomez Date: Fri, 20 May 2016 15:18:30 +0200 Subject: [PATCH 4/8] Add new error code tests --- src/test/compile-fail/E0062.rs | 20 ++++++++++++++++++++ src/test/compile-fail/E0063.rs | 18 ++++++++++++++++++ src/test/compile-fail/E0067.rs | 16 ++++++++++++++++ src/test/compile-fail/E0069.rs | 16 ++++++++++++++++ src/test/compile-fail/E0070.rs | 23 +++++++++++++++++++++++ src/test/compile-fail/E0071.rs | 16 ++++++++++++++++ src/test/compile-fail/E0072.rs | 17 +++++++++++++++++ src/test/compile-fail/E0075.rs | 17 +++++++++++++++++ src/test/compile-fail/E0076.rs | 17 +++++++++++++++++ src/test/compile-fail/E0077.rs | 17 +++++++++++++++++ src/test/compile-fail/E0079.rs | 16 ++++++++++++++++ src/test/compile-fail/E0080.rs | 17 +++++++++++++++++ src/test/compile-fail/E0081.rs | 18 ++++++++++++++++++ 13 files changed, 228 insertions(+) create mode 100644 src/test/compile-fail/E0062.rs create mode 100644 src/test/compile-fail/E0063.rs create mode 100644 src/test/compile-fail/E0067.rs create mode 100644 src/test/compile-fail/E0069.rs create mode 100644 src/test/compile-fail/E0070.rs create mode 100644 src/test/compile-fail/E0071.rs create mode 100644 src/test/compile-fail/E0072.rs create mode 100644 src/test/compile-fail/E0075.rs create mode 100644 src/test/compile-fail/E0076.rs create mode 100644 src/test/compile-fail/E0077.rs create mode 100644 src/test/compile-fail/E0079.rs create mode 100644 src/test/compile-fail/E0080.rs create mode 100644 src/test/compile-fail/E0081.rs diff --git a/src/test/compile-fail/E0062.rs b/src/test/compile-fail/E0062.rs new file mode 100644 index 0000000000000..86ec7db14b5c1 --- /dev/null +++ b/src/test/compile-fail/E0062.rs @@ -0,0 +1,20 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Foo { + x: i32 +} + +fn main() { + let x = Foo { + x: 0, + x: 0, //~ ERROR E0062 + }; +} diff --git a/src/test/compile-fail/E0063.rs b/src/test/compile-fail/E0063.rs new file mode 100644 index 0000000000000..c94f807d807ca --- /dev/null +++ b/src/test/compile-fail/E0063.rs @@ -0,0 +1,18 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Foo { + x: i32, + y: i32 +} + +fn main() { + let x = Foo { x: 0 }; //~ ERROR E0063 +} diff --git a/src/test/compile-fail/E0067.rs b/src/test/compile-fail/E0067.rs new file mode 100644 index 0000000000000..a3fc30ee1c71a --- /dev/null +++ b/src/test/compile-fail/E0067.rs @@ -0,0 +1,16 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::collections::LinkedList; + +fn main() { + LinkedList::new() += 1; //~ ERROR E0368 + //~^ ERROR E0067 +} diff --git a/src/test/compile-fail/E0069.rs b/src/test/compile-fail/E0069.rs new file mode 100644 index 0000000000000..d164d86348784 --- /dev/null +++ b/src/test/compile-fail/E0069.rs @@ -0,0 +1,16 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn foo() -> u8 { + return; //~ ERROR E0069 +} + +fn main() { +} diff --git a/src/test/compile-fail/E0070.rs b/src/test/compile-fail/E0070.rs new file mode 100644 index 0000000000000..ba66bd03aef9d --- /dev/null +++ b/src/test/compile-fail/E0070.rs @@ -0,0 +1,23 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +const SOME_CONST : i32 = 12; + +fn some_other_func() {} + +fn some_function() { + SOME_CONST = 14; //~ ERROR E0070 + 1 = 3; //~ ERROR E0070 + some_other_func() = 4; //~ ERROR E0070 + //~^ ERROR E0308 +} + +fn main() { +} diff --git a/src/test/compile-fail/E0071.rs b/src/test/compile-fail/E0071.rs new file mode 100644 index 0000000000000..658c8fb155114 --- /dev/null +++ b/src/test/compile-fail/E0071.rs @@ -0,0 +1,16 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +enum Foo { FirstValue(i32) } + +fn main() { + let u = Foo::FirstValue { value: 0 }; //~ ERROR E0071 + let t = u32 { value: 4 }; //~ ERROR E0071 +} diff --git a/src/test/compile-fail/E0072.rs b/src/test/compile-fail/E0072.rs new file mode 100644 index 0000000000000..2f96ba1046d74 --- /dev/null +++ b/src/test/compile-fail/E0072.rs @@ -0,0 +1,17 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct ListNode { //~ ERROR E0072 + head: u8, + tail: Option, +} + +fn main() { +} diff --git a/src/test/compile-fail/E0075.rs b/src/test/compile-fail/E0075.rs new file mode 100644 index 0000000000000..d7783904e2e98 --- /dev/null +++ b/src/test/compile-fail/E0075.rs @@ -0,0 +1,17 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(repr_simd)] + +#[repr(simd)] +struct Bad; //~ ERROR E0075 + +fn main() { +} diff --git a/src/test/compile-fail/E0076.rs b/src/test/compile-fail/E0076.rs new file mode 100644 index 0000000000000..b0f02a03e0051 --- /dev/null +++ b/src/test/compile-fail/E0076.rs @@ -0,0 +1,17 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(repr_simd)] + +#[repr(simd)] +struct Bad(u16, u32, u32); //~ ERROR E0076 + +fn main() { +} diff --git a/src/test/compile-fail/E0077.rs b/src/test/compile-fail/E0077.rs new file mode 100644 index 0000000000000..b074e90b2c01f --- /dev/null +++ b/src/test/compile-fail/E0077.rs @@ -0,0 +1,17 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(repr_simd)] + +#[repr(simd)] +struct Bad(String); //~ ERROR E0077 + +fn main() { +} diff --git a/src/test/compile-fail/E0079.rs b/src/test/compile-fail/E0079.rs new file mode 100644 index 0000000000000..23957c72ff00e --- /dev/null +++ b/src/test/compile-fail/E0079.rs @@ -0,0 +1,16 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +enum Foo { + Q = "32" //~ ERROR E0079 +} + +fn main() { +} diff --git a/src/test/compile-fail/E0080.rs b/src/test/compile-fail/E0080.rs new file mode 100644 index 0000000000000..0329209d44bc7 --- /dev/null +++ b/src/test/compile-fail/E0080.rs @@ -0,0 +1,17 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +enum Enum { + X = (1 << 500), //~ ERROR E0080 + Y = (1 / 0) //~ ERROR E0080 +} + +fn main() { +} diff --git a/src/test/compile-fail/E0081.rs b/src/test/compile-fail/E0081.rs new file mode 100644 index 0000000000000..b63265564b334 --- /dev/null +++ b/src/test/compile-fail/E0081.rs @@ -0,0 +1,18 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +enum Enum { + P = 3, + X = 3, //~ ERROR E0081 + Y = 5 +} + +fn main() { +} From 01dc9f0be4b3ab12d5c018548380ea6781350ec2 Mon Sep 17 00:00:00 2001 From: Alex Ozdemir Date: Sun, 22 May 2016 12:47:53 -0700 Subject: [PATCH 5/8] Changed toggle all sections key to `T` Allows both `T` and `t`. It had been [Shift]+[+] before. --- src/librustdoc/html/layout.rs | 2 +- src/librustdoc/html/static/main.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 265ed6be1552d..0af64573926de 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -103,7 +103,7 @@ r##"
Move down in search results
Go to active search result
-
+
+
T
Collapse/expand all sections
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 0ec5cab78bc7b..e8f23c4709d43 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -124,7 +124,8 @@ focusSearchBar(); break; - case "+": + case "t": + case "T": toggleAllDocs(); break; From 57ab0edaf0514646c8ca95d436c1edf97edfdc23 Mon Sep 17 00:00:00 2001 From: Alex Ozdemir Date: Sun, 22 May 2016 18:11:15 -0700 Subject: [PATCH 6/8] Fixed shortcut handling. Reverted to [Shift]+[+=] Realized browsers use [Ctrl]+[+=] for zoom, so using [Shift]+[+=] for collapse/expand was not necessarily a conflict. Also a bugfix. --- src/librustdoc/html/layout.rs | 2 +- src/librustdoc/html/static/main.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 0af64573926de..265ed6be1552d 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -103,7 +103,7 @@ r##"
Move down in search results
Go to active search result
-
T
+
+
Collapse/expand all sections
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index e8f23c4709d43..14661dbaec4c5 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -124,8 +124,8 @@ focusSearchBar(); break; - case "t": - case "T": + case "+": + ev.preventDefault(); toggleAllDocs(); break; From bb94e6a7391f0d3dc669a8c838ac77669e1586c7 Mon Sep 17 00:00:00 2001 From: Tamir Bahar Date: Mon, 23 May 2016 14:42:47 +0300 Subject: [PATCH 7/8] Fixed link in Rust Book (no-stdlib) Fix a broken link in the rust book. --- src/doc/book/no-stdlib.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/book/no-stdlib.md b/src/doc/book/no-stdlib.md index 43bd0507ebbb6..9823a0b6d6355 100644 --- a/src/doc/book/no-stdlib.md +++ b/src/doc/book/no-stdlib.md @@ -84,4 +84,4 @@ which do not trigger a panic can be assured that this function is never called. The second function, `panic_fmt`, is also used by the failure mechanisms of the compiler. -[unwind]: https://github.com/rust-lang/rust/blob/master/src/libstd/sys/common/unwind/gcc.rs +[unwind]: https://github.com/rust-lang/rust/blob/master/src/libpanic_unwind/gcc.rs From 7d78436359da05a256107a179c7098fef465dd7c Mon Sep 17 00:00:00 2001 From: Nick Hamann Date: Tue, 17 May 2016 02:59:18 -0500 Subject: [PATCH 8/8] Improve the long explanation of E0207. The previous explanation does not seem to explain what it means for an implementation parameter to be used or unused. The new explanation lists the three ways specific ways by which an impl parameter becomes constrained (taken from RFC 447). This also adds a link to RFC 447. The explanation has two different examples. The first is adapted from RFC 447, and shows an instance of E0207 on a impl for a type. The second one is a trait impl example adapted from issue #22834. Closes #33650 --- src/librustc_typeck/diagnostics.rs | 126 +++++++++++++++++++++++++---- 1 file changed, 111 insertions(+), 15 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 5f2997a86a9f2..251a92b9ef113 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -2387,39 +2387,135 @@ impl Copy for &'static Bar { } // error "##, E0207: r##" -You declared an unused type parameter when implementing a trait on an object. -Erroneous code example: +Any type parameter or lifetime parameter of an `impl` must meet at least one of +the following criteria: + + - it appears in the self type of the impl + - for a trait impl, it appears in the trait reference + - it is bound as an associated type + +### Error example 1 + +Suppose we have a struct `Foo` and we would like to define some methods for it. +The following definition leads to a compiler error: ```compile_fail -trait MyTrait { - fn get(&self) -> usize; +struct Foo; + +impl Foo { +// error: the type parameter `T` is not constrained by the impl trait, self +// type, or predicates [E0207] + fn get(&self) -> T { + ::default() + } } +``` + +The problem is that the parameter `T` does not appear in the self type (`Foo`) +of the impl. In this case, we can fix the error by moving the type parameter +from the `impl` to the method `get`: + +``` struct Foo; -impl MyTrait for Foo { - fn get(&self) -> usize { - 0 +// Move the type parameter from the impl to the method +impl Foo { + fn get(&self) -> T { + ::default() } } ``` -Please check your object definition and remove unused type -parameter(s). Example: +### Error example 2 +As another example, suppose we have a `Maker` trait and want to establish a +type `FooMaker` that makes `Foo`s: + +```compile_fail +trait Maker { + type Item; + fn make(&mut self) -> Self::Item; +} + +struct Foo { + foo: T +} + +struct FooMaker; + +impl Maker for FooMaker { +// error: the type parameter `T` is not constrained by the impl trait, self +// type, or predicates [E0207] + type Item = Foo; + + fn make(&mut self) -> Foo { + Foo { foo: ::default() } + } +} ``` -trait MyTrait { - fn get(&self) -> usize; + +This fails to compile because `T` does not appear in the trait or in the +implementing type. + +One way to work around this is to introduce a phantom type parameter into +`FooMaker`, like so: + +``` +use std::marker::PhantomData; + +trait Maker { + type Item; + fn make(&mut self) -> Self::Item; } -struct Foo; +struct Foo { + foo: T +} -impl MyTrait for Foo { - fn get(&self) -> usize { - 0 +// Add a type parameter to `FooMaker` +struct FooMaker { + phantom: PhantomData, +} + +impl Maker for FooMaker { + type Item = Foo; + + fn make(&mut self) -> Foo { + Foo { + foo: ::default(), + } + } +} +``` + +Another way is to do away with the associated type in `Maker` and use an input +type parameter instead: + +``` +// Use a type parameter instead of an associated type here +trait Maker { + fn make(&mut self) -> Item; +} + +struct Foo { + foo: T +} + +struct FooMaker; + +impl Maker> for FooMaker { + fn make(&mut self) -> Foo { + Foo { foo: ::default() } } } ``` + +### Additional information + +For more information, please see [RFC 447]. + +[RFC 447]: https://github.com/rust-lang/rfcs/blob/master/text/0447-no-unused-impl-parameters.md "##, E0210: r##"