about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-05-24 10:39:00 -0700
committerbors <bors@rust-lang.org>2016-05-24 10:39:00 -0700
commit8393d99c356e51128e0125aa23a7824d6ff513b2 (patch)
treeccda07c630297b9a42f3c3fa439c0bbf9ccdc0b3
parentdd6e8d45e183861d44ed91a99f0a50403b2776a3 (diff)
parent46138352e68070af94d5379f9a1f28c24dec1e96 (diff)
downloadrust-8393d99c356e51128e0125aa23a7824d6ff513b2.tar.gz
rust-8393d99c356e51128e0125aa23a7824d6ff513b2.zip
Auto merge of #33833 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 7 pull requests

- Successful merges: #33692, #33759, #33779, #33781, #33797, #33810, #33832
- Failed merges:
-rw-r--r--src/doc/book/no-stdlib.md2
-rw-r--r--src/doc/book/primitive-types.md2
-rw-r--r--src/librustc_typeck/diagnostics.rs150
-rw-r--r--src/librustdoc/html/static/main.js1
-rw-r--r--src/test/compile-fail/E0062.rs20
-rw-r--r--src/test/compile-fail/E0063.rs18
-rw-r--r--src/test/compile-fail/E0067.rs16
-rw-r--r--src/test/compile-fail/E0069.rs16
-rw-r--r--src/test/compile-fail/E0070.rs23
-rw-r--r--src/test/compile-fail/E0071.rs16
-rw-r--r--src/test/compile-fail/E0072.rs17
-rw-r--r--src/test/compile-fail/E0075.rs17
-rw-r--r--src/test/compile-fail/E0076.rs17
-rw-r--r--src/test/compile-fail/E0077.rs17
-rw-r--r--src/test/compile-fail/E0079.rs16
-rw-r--r--src/test/compile-fail/E0080.rs17
-rw-r--r--src/test/compile-fail/E0081.rs18
17 files changed, 353 insertions, 30 deletions
diff --git a/src/doc/book/no-stdlib.md b/src/doc/book/no-stdlib.md
index 43bd0507ebb..9823a0b6d63 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
diff --git a/src/doc/book/primitive-types.md b/src/doc/book/primitive-types.md
index 2a4b7ba37f2..b6a123bb367 100644
--- a/src/doc/book/primitive-types.md
+++ b/src/doc/book/primitive-types.md
@@ -175,8 +175,6 @@ You can use a combo of `&` and `[]` to create a slice from various things. The
 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
diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs
index 45aec9558fe..40b9b0e01ab 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, 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);
 ```
 "##,
@@ -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<T: Default> Foo {
+// error: the type parameter `T` is not constrained by the impl trait, self
+// type, or predicates [E0207]
+    fn get(&self) -> T {
+        <T as Default>::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<T> MyTrait for Foo {
-    fn get(&self) -> usize {
-        0
+// Move the type parameter from the impl to the method
+impl Foo {
+    fn get<T: Default>(&self) -> T {
+        <T as Default>::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<T> {
+    foo: T
+}
+
+struct FooMaker;
 
+impl<T: Default> Maker for FooMaker {
+// error: the type parameter `T` is not constrained by the impl trait, self
+// type, or predicates [E0207]
+    type Item = Foo<T>;
+
+    fn make(&mut self) -> Foo<T> {
+        Foo { foo: <T as Default>::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<T> {
+    foo: T
+}
 
-impl MyTrait for Foo {
-    fn get(&self) -> usize {
-        0
+// Add a type parameter to `FooMaker`
+struct FooMaker<T> {
+    phantom: PhantomData<T>,
+}
+
+impl<T: Default> Maker for FooMaker<T> {
+    type Item = Foo<T>;
+
+    fn make(&mut self) -> Foo<T> {
+        Foo {
+            foo: <T as Default>::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<Item> {
+    fn make(&mut self) -> Item;
+}
+
+struct Foo<T> {
+    foo: T
+}
+
+struct FooMaker;
+
+impl<T: Default> Maker<Foo<T>> for FooMaker {
+    fn make(&mut self) -> Foo<T> {
+        Foo { foo: <T as Default>::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##"
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index 0ec5cab78bc..14661dbaec4 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -125,6 +125,7 @@
             break;
 
         case "+":
+            ev.preventDefault();
             toggleAllDocs();
             break;
 
diff --git a/src/test/compile-fail/E0062.rs b/src/test/compile-fail/E0062.rs
new file mode 100644
index 00000000000..86ec7db14b5
--- /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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 00000000000..c94f807d807
--- /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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 00000000000..a3fc30ee1c7
--- /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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 00000000000..d164d863487
--- /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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 00000000000..ba66bd03aef
--- /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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 00000000000..658c8fb1551
--- /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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 00000000000..2f96ba1046d
--- /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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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<ListNode>,
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/E0075.rs b/src/test/compile-fail/E0075.rs
new file mode 100644
index 00000000000..d7783904e2e
--- /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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 00000000000..b0f02a03e00
--- /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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 00000000000..b074e90b2c0
--- /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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 00000000000..23957c72ff0
--- /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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 00000000000..0329209d44b
--- /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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 00000000000..b63265564b3
--- /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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() {
+}