]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #34401 - GuillaumeGomez:err-codes, r=brson
authorbors <bors@rust-lang.org>
Fri, 24 Jun 2016 22:42:13 +0000 (15:42 -0700)
committerGitHub <noreply@github.com>
Fri, 24 Jun 2016 22:42:13 +0000 (15:42 -0700)
Add error code flags

r? @brson

cc @steveklabnik
cc @jonathandturner

src/librustc/diagnostics.rs

index eb51043fcd025268a275127e36085711ba580699..538613c7fac9126ced763527e6fea95ca5f6e727 100644 (file)
@@ -298,7 +298,7 @@ trait Super<A> {
 
 Consider the following erroneous definition of a type for a list of bytes:
 
-```compile_fail
+```compile_fail,E0072
 // error, invalid recursive struct type
 struct ListNode {
     head: u8,
@@ -331,7 +331,7 @@ struct ListNode {
 You tried to give a type parameter to a type which doesn't need it. Erroneous
 code example:
 
-```compile_fail
+```compile_fail,E0109
 type X = u32<i32>; // error: type parameters are not allowed on this type
 ```
 
@@ -352,7 +352,7 @@ struct ListNode {
 You tried to give a lifetime parameter to a type which doesn't need it.
 Erroneous code example:
 
-```compile_fail
+```compile_fail,E0110
 type X = u32<'static>; // error: lifetime parameters are not allowed on
                        //        this type
 ```
@@ -370,7 +370,7 @@ struct ListNode {
 
 Erroneous code example:
 
-```compile_fail
+```compile_fail,E0133
 unsafe fn f() { return; } // This is the unsafe code
 
 fn main() {
@@ -410,7 +410,7 @@ fn main() {
 
 Erroneous code example:
 
-```compile_fail
+```compile_fail,E0137
 #![feature(main)]
 
 #[main]
@@ -437,7 +437,7 @@ fn f() {} // ok!
 
 Erroneous code example:
 
-```compile_fail
+```compile_fail,E0138
 #![feature(start)]
 
 #[start]
@@ -460,8 +460,7 @@ fn foo(argc: isize, argv: *const *const u8) -> isize { 0 } // ok!
 ```
 "##,
 
-// FIXME link this to the relevant turpl chapters for instilling fear of the
-//       transmute gods in the user
+// isn't thrown anymore
 E0139: r##"
 There are various restrictions on transmuting between types in Rust; for example
 types being transmuted must have the same size. To apply all these restrictions,
@@ -470,11 +469,13 @@ fn foo(argc: isize, argv: *const *const u8) -> isize { 0 } // ok!
 
 So, for example, the following is not allowed:
 
-```compile_fail
+```
+use std::mem::transmute;
+
 struct Foo<T>(Vec<T>);
 
 fn foo<T>(x: Vec<T>) {
-    // we are transmuting between Vec<T> and Foo<T> here
+    // we are transmuting between Vec<T> and Foo<F> here
     let y: Foo<T> = unsafe { transmute(x) };
     // do something with y
 }
@@ -542,7 +543,7 @@ fn foo<T: MyTransmutableType>(x: Vec<T>) {
 
 Erroneous code example:
 
-```compile_fail
+```compile_fail,E0152
 #![feature(lang_items)]
 
 #[lang = "panic_fmt"]
@@ -567,7 +568,7 @@ fn foo<T: MyTransmutableType>(x: Vec<T>) {
 An associated type binding was done outside of the type parameter declaration
 and `where` clause. Erroneous code example:
 
-```compile_fail
+```compile_fail,E0229
 pub trait Foo {
     type A;
     fn boo(&self) -> <Self as Foo>::A;
@@ -604,7 +605,7 @@ fn baz<I>(x: &<I as Foo>::A) where I: Foo<A=Bar> {}
 
 These two examples illustrate the problem:
 
-```compile_fail
+```compile_fail,E0261
 // error, use of undeclared lifetime name `'a`
 fn foo(x: &'a str) { }
 
@@ -630,7 +631,7 @@ struct Foo<'a> {
 because the `'static` lifetime is a special built-in lifetime name denoting
 the lifetime of the entire program, this is an error:
 
-```compile_fail
+```compile_fail,E0262
 // error, invalid lifetime parameter name `'static`
 fn foo<'static>(x: &'static str) { }
 ```
@@ -640,7 +641,7 @@ fn foo<'static>(x: &'static str) { }
 A lifetime name cannot be declared more than once in the same scope. For
 example:
 
-```compile_fail
+```compile_fail,E0263
 // error, lifetime name `'a` declared twice in the same scope
 fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str) { }
 ```
@@ -649,7 +650,7 @@ fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str) { }
 E0264: r##"
 An unknown external lang item was used. Erroneous code example:
 
-```compile_fail
+```compile_fail,E0264
 #![feature(lang_items)]
 
 extern "C" {
@@ -675,12 +676,9 @@ fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str) { }
 Functions must eventually return a value of their return type. For example, in
 the following function:
 
-```compile_fail
-fn foo(x: u8) -> u8 {
-    if x > 0 {
-        x // alternatively, `return x`
-    }
-    // nothing here
+```compile_fail,E0269
+fn abracada_FAIL() -> String {
+    "this won't work".to_string();
 }
 ```
 
@@ -806,7 +804,7 @@ fn foo() -> ! {
 
 Here is a basic example:
 
-```compile_fail
+```compile_fail,E0271
 trait Trait { type AssociatedType; }
 
 fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
@@ -947,6 +945,8 @@ fn foo<T>(t: T) where T: Trait<AssociatedType = &'static str> {
 compiled:
 
 ```compile_fail
+#![feature(on_unimplemented)]
+
 fn foo<T: Index<u8>>(x: T){}
 
 #[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
@@ -977,6 +977,8 @@ trait Index<Idx> { /* ... */ }
 compiled:
 
 ```compile_fail
+#![feature(on_unimplemented)]
+
 fn foo<T: Index<u8>>(x: T){}
 
 #[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
@@ -1005,6 +1007,8 @@ trait Index<Idx> { /* ... */ }
 compiled:
 
 ```compile_fail
+#![feature(on_unimplemented)]
+
 fn foo<T: Index<u8>>(x: T){}
 
 #[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
@@ -1028,7 +1032,7 @@ trait Index<Idx> { /* ... */ }
 
 For example, in the following code:
 
-```compile_fail
+```compile_fail,E0275
 trait Foo {}
 
 struct Bar<T>(T);
@@ -1048,7 +1052,7 @@ impl<T> Foo for T where Bar<T>: Foo {}
 This error occurs when a bound in an implementation of a trait does not match
 the bounds specified in the original trait. For example:
 
-```compile_fail
+```compile_fail,E0276
 trait Foo {
     fn foo<T>(x: T);
 }
@@ -1070,7 +1074,7 @@ fn foo<T>(x: T) where T: Copy {}
 You tried to use a type which doesn't implement some trait in a place which
 expected that trait. Erroneous code example:
 
-```compile_fail
+```compile_fail,E0277
 // here we declare the Foo trait with a bar method
 trait Foo {
     fn bar(&self);
@@ -1113,7 +1117,7 @@ fn main() {
 
 Or in a generic context, an erroneous code example would look like:
 
-```compile_fail
+```compile_fail,E0277
 fn some_func<T>(foo: T) {
     println!("{:?}", foo); // error: the trait `core::fmt::Debug` is not
                            //        implemented for the type `T`
@@ -1159,7 +1163,7 @@ fn main() {
 which expected that trait. This error typically occurs when working with
 `Fn`-based types. Erroneous code example:
 
-```compile_fail
+```compile_fail,E0281
 fn foo<F: Fn()>(x: F) { }
 
 fn main() {
@@ -1185,7 +1189,7 @@ fn main() {
 implemented by `Vec` and `String` among others. Consider the following snippet
 that reverses the characters of a string:
 
-```compile_fail
+```compile_fail,E0282
 let x = "hello".chars().rev().collect();
 ```
 
@@ -1222,7 +1226,7 @@ fn main() {
 case it is not always possible to use a type annotation, because all candidates
 have the same return type. For instance:
 
-```compile_fail
+```compile_fail,E0282
 struct Foo<T> {
     num: T,
 }
@@ -1248,7 +1252,7 @@ fn baz() {
 
 For example:
 
-```compile_fail
+```compile_fail,E0283
 trait Generator {
     fn create() -> u32;
 }
@@ -1296,10 +1300,22 @@ fn main() {
 
 E0296: r##"
 This error indicates that the given recursion limit could not be parsed. Ensure
-that the value provided is a positive integer between quotes, like so:
+that the value provided is a positive integer between quotes.
+
+Erroneous code example:
+
+```compile_fail,E0296
+#![recursion_limit]
+
+fn main() {}
+```
+
+And a working example:
 
 ```
 #![recursion_limit="1000"]
+
+fn main() {}
 ```
 "##,
 
@@ -1312,7 +1328,7 @@ fn main() {
 
 For example:
 
-```compile_fail
+```compile_fail,E0308
 let x: i32 = "I am not a number!";
 //     ~~~   ~~~~~~~~~~~~~~~~~~~~
 //      |             |
@@ -1325,7 +1341,7 @@ fn main() {
 Another situation in which this occurs is when you attempt to use the `try!`
 macro inside a function that does not return a `Result<T, E>`:
 
-```compile_fail
+```compile_fail,E0308
 use std::fs::File;
 
 fn main() {
@@ -1353,7 +1369,7 @@ fn main() {
 must be as long as the data needs to be alive, and missing the constraint that
 denotes this will cause this error.
 
-```compile_fail
+```compile_fail,E0309
 // This won't compile because T is not constrained, meaning the data
 // stored in it is not guaranteed to last as long as the reference
 struct Foo<'a, T> {
@@ -1376,7 +1392,7 @@ struct Foo<'a, T: 'a> {
 must be as long as the data needs to be alive, and missing the constraint that
 denotes this will cause this error.
 
-```compile_fail
+```compile_fail,E0310
 // This won't compile because T is not constrained to the static lifetime
 // the reference needs
 struct Foo<T> {
@@ -1430,7 +1446,7 @@ fn foo<'a>(arg: &Box<SomeTrait+'a>) { ... }
 E0452: r##"
 An invalid lint attribute has been given. Erroneous code example:
 
-```compile_fail
+```compile_fail,E0452
 #![allow(foo = "")] // error: malformed lint attribute
 ```
 
@@ -1450,7 +1466,7 @@ fn foo<'a>(arg: &Box<SomeTrait+'a>) { ... }
 
 Example of erroneous code:
 
-```compile_fail
+```compile_fail,E0453
 #![forbid(non_snake_case)]
 
 #[allow(non_snake_case)]
@@ -1492,7 +1508,7 @@ fn main() {
 E0496: r##"
 A lifetime name is shadowing another lifetime name. Erroneous code example:
 
-```compile_fail
+```compile_fail,E0496
 struct Foo<'a> {
     a: &'a i32,
 }
@@ -1539,7 +1555,7 @@ fn foo() {}
 Transmute with two differently sized types was attempted. Erroneous code
 example:
 
-```compile_fail
+```compile_fail,E0512
 fn takes_u8(_: u8) {}
 
 fn main() {
@@ -1567,7 +1583,7 @@ fn main() {
 
 Examples of erroneous code:
 
-```compile_fail
+```compile_fail,E0517
 #[repr(C)]
 type Foo = u8;
 
@@ -1615,7 +1631,7 @@ impl Foo {
 
 Examples of erroneous code:
 
-```compile_fail
+```compile_fail,E0518
 #[inline(always)]
 struct Foo;
 
@@ -1642,7 +1658,7 @@ impl Foo {
 invoked (such as the handler for out-of-bounds accesses when indexing a slice).
 Erroneous code example:
 
-```compile_fail
+```compile_fail,E0522
 #![feature(lang_items)]
 
 #[lang = "cookie"]