]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #35393 - GuillaumeGomez:err_codes2, r=jonathandturner
authorbors <bors@rust-lang.org>
Sat, 6 Aug 2016 19:29:28 +0000 (12:29 -0700)
committerGitHub <noreply@github.com>
Sat, 6 Aug 2016 19:29:28 +0000 (12:29 -0700)
Err codes

r? @jonathandturner

13 files changed:
src/librustc_const_eval/diagnostics.rs
src/test/compile-fail/E0271.rs [new file with mode: 0644]
src/test/compile-fail/E0275.rs [new file with mode: 0644]
src/test/compile-fail/E0276.rs [new file with mode: 0644]
src/test/compile-fail/E0277.rs [new file with mode: 0644]
src/test/compile-fail/E0281.rs [new file with mode: 0644]
src/test/compile-fail/E0282.rs [new file with mode: 0644]
src/test/compile-fail/E0283.rs [new file with mode: 0644]
src/test/compile-fail/E0296.rs [new file with mode: 0644]
src/test/compile-fail/E0297.rs [new file with mode: 0644]
src/test/compile-fail/E0301.rs [new file with mode: 0644]
src/test/compile-fail/E0302.rs [new file with mode: 0644]
src/test/compile-fail/E0303.rs [new file with mode: 0644]

index 45414c33c075448640ef116443fcaf58f23d4e0d..9cdc76f25a63f1a6b77cc446269daa3054b592f7 100644 (file)
@@ -25,8 +25,8 @@
 
 For example, the following `match` block has too many arms:
 
-```compile_fail
-match foo {
+```compile_fail,E0001
+match Some(0) {
     Some(bar) => {/* ... */}
     None => {/* ... */}
     _ => {/* ... */} // All possible cases have already been handled
@@ -108,7 +108,7 @@ fn foo(x: Option<String>) {
 required in order to assign values to match expressions, or alternatively,
 determine the flow of execution. Erroneous code example:
 
-```compile_fail
+```compile_fail,E0004
 enum Terminator {
     HastaLaVistaBaby,
     TalkToMyHand,
@@ -153,7 +153,7 @@ enum Terminator {
 Patterns used to bind names must be irrefutable, that is, they must guarantee
 that a name will be extracted in all cases. Erroneous code example:
 
-```compile_fail
+```compile_fail,E0005
 let x = Some(1);
 let Some(y) = x;
 // error: refutable pattern in local binding: `None` not covered
@@ -187,7 +187,7 @@ enum Terminator {
 moved into a variable called `op_string` while simultaneously requiring the
 inner `String` to be moved into a variable called `s`.
 
-```compile_fail
+```compile_fail,E0007
 let x = Some("s".to_string());
 
 match x {
@@ -205,7 +205,7 @@ enum Terminator {
 referenced in the pattern guard code. Doing so however would prevent the name
 from being available in the body of the match arm. Consider the following:
 
-```compile_fail
+```compile_fail,E0008
 match Some("hi".to_string()) {
     Some(s) if s.len() == 0 => {}, // use s.
     _ => {},
@@ -229,7 +229,7 @@ enum Terminator {
 Though this example seems innocuous and easy to solve, the problem becomes clear
 when it encounters functions which consume the value:
 
-```compile_fail
+```compile_fail,E0008
 struct A{}
 
 impl A {
@@ -283,7 +283,7 @@ fn main() {
 
 Erroneous code example:
 
-```compile_fail
+```compile_fail,E0009
 struct X { x: (), }
 
 let x = Some((X { x: () }, X { x: () }));
@@ -351,25 +351,25 @@ struct X { x: (), }
 match was successful. If the match is irrefutable (when it cannot fail to
 match), use a regular `let`-binding instead. For instance:
 
-```compile_fail
+```compile_fail,E0162
 struct Irrefutable(i32);
 let irr = Irrefutable(0);
 
 // This fails to compile because the match is irrefutable.
 if let Irrefutable(x) = irr {
     // This body will always be executed.
-    foo(x);
+    // ...
 }
 ```
 
 Try this instead:
 
-```ignore
+```
 struct Irrefutable(i32);
 let irr = Irrefutable(0);
 
 let Irrefutable(x) = irr;
-foo(x);
+println!("{}", x);
 ```
 "##,
 
@@ -378,7 +378,7 @@ struct X { x: (), }
 match was successful. If the match is irrefutable (when it cannot fail to
 match), use a regular `let`-binding inside a `loop` instead. For instance:
 
-```compile_fail
+```compile_fail,E0165
 struct Irrefutable(i32);
 let irr = Irrefutable(0);
 
@@ -455,7 +455,7 @@ enum Method { GET, POST }
 loop variable, consider using a `match` or `if let` inside the loop body. For
 instance:
 
-```compile_fail
+```compile_fail,E0297
 let xs : Vec<Option<i32>> = vec!(Some(1), None);
 
 // This fails because `None` is not covered.
@@ -497,7 +497,7 @@ enum Method { GET, POST }
 exhaustive. For instance, the following would not match any arm if mutable
 borrows were allowed:
 
-```compile_fail
+```compile_fail,E0301
 match Some(()) {
     None => { },
     option if option.take().is_none() => {
@@ -515,10 +515,10 @@ enum Method { GET, POST }
 exhaustive. For instance, the following would not match any arm if assignments
 were allowed:
 
-```compile_fail
+```compile_fail,E0302
 match Some(()) {
     None => { },
-    option if { option = None; false } { },
+    option if { option = None; false } => { },
     Some(_) => { } // When the previous match failed, the option became `None`.
 }
 ```
@@ -529,14 +529,18 @@ enum Method { GET, POST }
 Updates to the borrow checker in a future version of Rust may remove this
 restriction, but for now patterns must be rewritten without sub-bindings.
 
-```ignore
-// Before.
+Before:
+
+```compile_fail,E0303
 match Some("hi".to_string()) {
     ref op_string_ref @ Some(s) => {},
     None => {},
 }
+```
+
+After:
 
-// After.
+```
 match Some("hi".to_string()) {
     Some(ref s) => {
         let op_string_ref = &Some(s);
@@ -556,7 +560,7 @@ enum Method { GET, POST }
 constant expression that had to be evaluated. Attempting to divide by 0
 or causing integer overflow are two ways to induce this error. For example:
 
-```compile_fail
+```compile_fail,E0080
 enum Enum {
     X = (1 << 500),
     Y = (1 / 0)
@@ -575,7 +579,7 @@ enum Enum {
 In an array literal `[x; N]`, `N` is the number of elements in the array. This
 must be an unsigned integer. Erroneous code example:
 
-```compile_fail
+```compile_fail,E0306
 let x = [0i32; true]; // error: expected positive integer for repeat count,
                       //        found boolean
 ```
diff --git a/src/test/compile-fail/E0271.rs b/src/test/compile-fail/E0271.rs
new file mode 100644 (file)
index 0000000..d322c8b
--- /dev/null
@@ -0,0 +1,21 @@
+// 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 Trait { type AssociatedType; }
+
+fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
+    println!("in foo");
+}
+
+impl Trait for i8 { type AssociatedType = &'static str; }
+
+fn main() {
+    foo(3_i8); //~ ERROR E0271
+}
diff --git a/src/test/compile-fail/E0275.rs b/src/test/compile-fail/E0275.rs
new file mode 100644 (file)
index 0000000..8dfd1d9
--- /dev/null
@@ -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.
+
+trait Foo {}
+
+struct Bar<T>(T);
+
+impl<T> Foo for T where Bar<T>: Foo {} //~ ERROR E0275
+
+fn main() {
+}
diff --git a/src/test/compile-fail/E0276.rs b/src/test/compile-fail/E0276.rs
new file mode 100644 (file)
index 0000000..62e43b0
--- /dev/null
@@ -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.
+
+trait Foo {
+    fn foo<T>(x: T);
+}
+
+impl Foo for bool {
+    fn foo<T>(x: T) where T: Copy {} //~ ERROR E0276
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/E0277.rs b/src/test/compile-fail/E0277.rs
new file mode 100644 (file)
index 0000000..7737f12
--- /dev/null
@@ -0,0 +1,21 @@
+// 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 bar(&self);
+}
+
+fn some_func<T: Foo>(foo: T) {
+    foo.bar();
+}
+
+fn main() {
+    some_func(5i32); //~ ERROR E0277
+}
diff --git a/src/test/compile-fail/E0281.rs b/src/test/compile-fail/E0281.rs
new file mode 100644 (file)
index 0000000..d468cd3
--- /dev/null
@@ -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<F: Fn()>(x: F) { }
+
+fn main() {
+    foo(|y| { }); //~ ERROR E0281
+                  //~^ ERROR E0281
+}
diff --git a/src/test/compile-fail/E0282.rs b/src/test/compile-fail/E0282.rs
new file mode 100644 (file)
index 0000000..dfc7026
--- /dev/null
@@ -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 = "hello".chars().rev().collect(); //~ ERROR E0282
+}
diff --git a/src/test/compile-fail/E0283.rs b/src/test/compile-fail/E0283.rs
new file mode 100644 (file)
index 0000000..844c47f
--- /dev/null
@@ -0,0 +1,29 @@
+// 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 Generator {
+    fn create() -> u32;
+}
+
+struct Impl;
+
+impl Generator for Impl {
+    fn create() -> u32 { 1 }
+}
+
+struct AnotherImpl;
+
+impl Generator for AnotherImpl {
+    fn create() -> u32 { 2 }
+}
+
+fn main() {
+    let cont: u32 = Generator::create(); //~ ERROR E0283
+}
diff --git a/src/test/compile-fail/E0296.rs b/src/test/compile-fail/E0296.rs
new file mode 100644 (file)
index 0000000..562fd00
--- /dev/null
@@ -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.
+
+#![recursion_limit] //~ ERROR E0296
+
+fn main() {}
diff --git a/src/test/compile-fail/E0297.rs b/src/test/compile-fail/E0297.rs
new file mode 100644 (file)
index 0000000..43166c1
--- /dev/null
@@ -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() {
+    let xs : Vec<Option<i32>> = vec!(Some(1), None);
+
+    for Some(x) in xs {} //~ ERROR E0297
+}
diff --git a/src/test/compile-fail/E0301.rs b/src/test/compile-fail/E0301.rs
new file mode 100644 (file)
index 0000000..06e9828
--- /dev/null
@@ -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.
+
+fn main() {
+    match Some(()) {
+        None => { },
+        option if option.take().is_none() => {}, //~ ERROR E0301
+        Some(_) => { }
+    }
+}
diff --git a/src/test/compile-fail/E0302.rs b/src/test/compile-fail/E0302.rs
new file mode 100644 (file)
index 0000000..6a5ad40
--- /dev/null
@@ -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.
+
+fn main() {
+    match Some(()) {
+        None => { },
+        option if { option = None; false } => { }, //~ ERROR E0302
+        Some(_) => { }
+    }
+}
diff --git a/src/test/compile-fail/E0303.rs b/src/test/compile-fail/E0303.rs
new file mode 100644 (file)
index 0000000..67947fd
--- /dev/null
@@ -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.
+
+fn main() {
+    match Some("hi".to_string()) {
+        ref op_string_ref @ Some(s) => {}, //~ ERROR E0303
+                                           //~^ ERROR E0009
+        None => {},
+    }
+}