about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-08-15 11:35:01 -0700
committerGitHub <noreply@github.com>2016-08-15 11:35:01 -0700
commit197be89f367d1240d5f9cd9c4efd77812775354e (patch)
tree919ec95ce0c19082aa01241016a1dceeb2d69a46
parentf65d96fe3fa3cfae2cfc88be40f7416a22c88bf2 (diff)
parent92779194ed964d0f6de98980ae270b0090cdaeb8 (diff)
downloadrust-197be89f367d1240d5f9cd9c4efd77812775354e.tar.gz
rust-197be89f367d1240d5f9cd9c4efd77812775354e.zip
Auto merge of #35680 - GuillaumeGomez:err_codes, r=jonathandturner
Err codes

r? @jonathandturner
-rw-r--r--src/librustc_mir/diagnostics.rs26
-rw-r--r--src/test/compile-fail/E0394.rs15
-rw-r--r--src/test/compile-fail/E0395.rs17
-rw-r--r--src/test/compile-fail/E0396.rs16
-rw-r--r--src/test/compile-fail/E0401.rs18
-rw-r--r--src/test/compile-fail/E0403.rs14
-rw-r--r--src/test/compile-fail/E0404.rs17
-rw-r--r--src/test/compile-fail/E0405.rs16
-rw-r--r--src/test/compile-fail/E0407.rs23
-rw-r--r--src/test/compile-fail/E0408.rs18
-rw-r--r--src/test/compile-fail/E0409.rs19
-rw-r--r--src/test/compile-fail/E0411.rs13
-rw-r--r--src/test/compile-fail/E0412.rs14
-rw-r--r--src/test/compile-fail/E0415.rs14
-rw-r--r--src/test/compile-fail/E0416.rs15
-rw-r--r--src/test/compile-fail/E0422.rs13
16 files changed, 264 insertions, 4 deletions
diff --git a/src/librustc_mir/diagnostics.rs b/src/librustc_mir/diagnostics.rs
index 65d51d20528..4a731d898a9 100644
--- a/src/librustc_mir/diagnostics.rs
+++ b/src/librustc_mir/diagnostics.rs
@@ -188,12 +188,30 @@ avoid mutation if possible.
 "##,
 
 E0394: r##"
-From [RFC 246]:
+A static was referred to by value by another static.
 
- > It is invalid for a static to reference another static by value. It is
- > required that all references be borrowed.
+Erroneous code examples:
 
-[RFC 246]: https://github.com/rust-lang/rfcs/pull/246
+```compile_fail,E0394
+static A: u32 = 0;
+static B: u32 = A; // error: cannot refer to other statics by value, use the
+                   //        address-of operator or a constant instead
+```
+
+A static cannot be referred by value. To fix this issue, either use a
+constant:
+
+```
+const A: u32 = 0; // `A` is now a constant
+static B: u32 = A; // ok!
+```
+
+Or refer to `A` by reference:
+
+```
+static A: u32 = 0;
+static B: &'static u32 = &A; // ok!
+```
 "##,
 
 
diff --git a/src/test/compile-fail/E0394.rs b/src/test/compile-fail/E0394.rs
new file mode 100644
index 00000000000..1b86b8ad674
--- /dev/null
+++ b/src/test/compile-fail/E0394.rs
@@ -0,0 +1,15 @@
+// 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.
+
+static A: u32 = 0;
+static B: u32 = A; //~ ERROR E0394
+
+fn main() {
+}
diff --git a/src/test/compile-fail/E0395.rs b/src/test/compile-fail/E0395.rs
new file mode 100644
index 00000000000..6ab66313a04
--- /dev/null
+++ b/src/test/compile-fail/E0395.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.
+
+static FOO: i32 = 42;
+static BAR: i32 = 42;
+
+static BAZ: bool = { (&FOO as *const i32) == (&BAR as *const i32) }; //~ ERROR E0395
+
+fn main() {
+}
diff --git a/src/test/compile-fail/E0396.rs b/src/test/compile-fail/E0396.rs
new file mode 100644
index 00000000000..7f34acdfb90
--- /dev/null
+++ b/src/test/compile-fail/E0396.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.
+
+const REG_ADDR: *const u8 = 0x5f3759df as *const u8;
+
+const VALUE: u8 = unsafe { *REG_ADDR }; //~ ERROR E0396
+
+fn main() {
+}
diff --git a/src/test/compile-fail/E0401.rs b/src/test/compile-fail/E0401.rs
new file mode 100644
index 00000000000..09bc950efd2
--- /dev/null
+++ b/src/test/compile-fail/E0401.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.
+
+fn foo<T>(x: T) {
+    fn bar(y: T) { //~ ERROR E0401
+    }
+    bar(x);
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/E0403.rs b/src/test/compile-fail/E0403.rs
new file mode 100644
index 00000000000..6a68013dc6f
--- /dev/null
+++ b/src/test/compile-fail/E0403.rs
@@ -0,0 +1,14 @@
+// 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<T, T>(s: T, u: T) {} //~ ERROR E0403
+
+fn main() {
+}
diff --git a/src/test/compile-fail/E0404.rs b/src/test/compile-fail/E0404.rs
new file mode 100644
index 00000000000..1c088a71d7d
--- /dev/null
+++ b/src/test/compile-fail/E0404.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 Foo;
+struct Bar;
+
+impl Foo for Bar {} //~ ERROR E0404
+
+fn main() {
+}
diff --git a/src/test/compile-fail/E0405.rs b/src/test/compile-fail/E0405.rs
new file mode 100644
index 00000000000..45d4b219ba8
--- /dev/null
+++ b/src/test/compile-fail/E0405.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.
+
+struct Foo;
+
+impl SomeTrait for Foo {} //~ ERROR E0405
+
+fn main() {
+}
diff --git a/src/test/compile-fail/E0407.rs b/src/test/compile-fail/E0407.rs
new file mode 100644
index 00000000000..b861cf1b378
--- /dev/null
+++ b/src/test/compile-fail/E0407.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.
+
+trait Foo {
+    fn a();
+}
+
+struct Bar;
+
+impl Foo for Bar {
+    fn a() {}
+    fn b() {} //~ ERROR E0407
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/E0408.rs b/src/test/compile-fail/E0408.rs
new file mode 100644
index 00000000000..43f6d9d757d
--- /dev/null
+++ b/src/test/compile-fail/E0408.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.
+
+fn main() {
+    let x = Some(0);
+
+    match x {
+        Some(y) | None => {} //~ ERROR E0408
+        _ => ()
+    }
+}
diff --git a/src/test/compile-fail/E0409.rs b/src/test/compile-fail/E0409.rs
new file mode 100644
index 00000000000..366ad152072
--- /dev/null
+++ b/src/test/compile-fail/E0409.rs
@@ -0,0 +1,19 @@
+// 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 main() {
+    let x = (0, 2);
+
+    match x {
+        (0, ref y) | (y, 0) => {} //~ ERROR E0409
+                                  //~^ ERROR E0308
+        _ => ()
+    }
+}
diff --git a/src/test/compile-fail/E0411.rs b/src/test/compile-fail/E0411.rs
new file mode 100644
index 00000000000..187986fbadb
--- /dev/null
+++ b/src/test/compile-fail/E0411.rs
@@ -0,0 +1,13 @@
+// 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 main() {
+    <Self>::foo; //~ ERROR E0411
+}
diff --git a/src/test/compile-fail/E0412.rs b/src/test/compile-fail/E0412.rs
new file mode 100644
index 00000000000..f62901cac31
--- /dev/null
+++ b/src/test/compile-fail/E0412.rs
@@ -0,0 +1,14 @@
+// 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.
+
+impl Something {} //~ ERROR E0412
+
+fn main() {
+}
diff --git a/src/test/compile-fail/E0415.rs b/src/test/compile-fail/E0415.rs
new file mode 100644
index 00000000000..2a5f0d3c229
--- /dev/null
+++ b/src/test/compile-fail/E0415.rs
@@ -0,0 +1,14 @@
+// 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(f: i32, f: i32) {} //~ ERROR E0415
+
+fn main() {
+}
diff --git a/src/test/compile-fail/E0416.rs b/src/test/compile-fail/E0416.rs
new file mode 100644
index 00000000000..91077ab37f3
--- /dev/null
+++ b/src/test/compile-fail/E0416.rs
@@ -0,0 +1,15 @@
+// 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 main() {
+    match (1, 2) {
+        (x, x) => {} //~ ERROR E0416
+    }
+}
diff --git a/src/test/compile-fail/E0422.rs b/src/test/compile-fail/E0422.rs
new file mode 100644
index 00000000000..d1cb7fd9640
--- /dev/null
+++ b/src/test/compile-fail/E0422.rs
@@ -0,0 +1,13 @@
+// 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 main () {
+    let x = Foo { x: 1, y: 2 }; //~ ERROR E0422
+}