Skip to content

Commit d011290

Browse files
authored
Auto merge of rust-lang#34401 - GuillaumeGomez:err-codes, r=brson
Add error code flags r? @brson cc @steveklabnik cc @jonathandturner
2 parents dc9112f + 8f987ab commit d011290

File tree

1 file changed

+59
-43
lines changed

1 file changed

+59
-43
lines changed

src/librustc/diagnostics.rs

Lines changed: 59 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ the pointer, the size of the type would need to be unbounded.
298298
299299
Consider the following erroneous definition of a type for a list of bytes:
300300
301-
```compile_fail
301+
```compile_fail,E0072
302302
// error, invalid recursive struct type
303303
struct ListNode {
304304
head: u8,
@@ -331,7 +331,7 @@ E0109: r##"
331331
You tried to give a type parameter to a type which doesn't need it. Erroneous
332332
code example:
333333
334-
```compile_fail
334+
```compile_fail,E0109
335335
type X = u32<i32>; // error: type parameters are not allowed on this type
336336
```
337337
@@ -352,7 +352,7 @@ E0110: r##"
352352
You tried to give a lifetime parameter to a type which doesn't need it.
353353
Erroneous code example:
354354
355-
```compile_fail
355+
```compile_fail,E0110
356356
type X = u32<'static>; // error: lifetime parameters are not allowed on
357357
// this type
358358
```
@@ -370,7 +370,7 @@ Unsafe code was used outside of an unsafe function or block.
370370
371371
Erroneous code example:
372372
373-
```compile_fail
373+
```compile_fail,E0133
374374
unsafe fn f() { return; } // This is the unsafe code
375375
376376
fn main() {
@@ -410,7 +410,7 @@ More than one function was declared with the `#[main]` attribute.
410410
411411
Erroneous code example:
412412
413-
```compile_fail
413+
```compile_fail,E0137
414414
#![feature(main)]
415415
416416
#[main]
@@ -437,7 +437,7 @@ More than one function was declared with the `#[start]` attribute.
437437
438438
Erroneous code example:
439439
440-
```compile_fail
440+
```compile_fail,E0138
441441
#![feature(start)]
442442
443443
#[start]
@@ -460,8 +460,7 @@ fn foo(argc: isize, argv: *const *const u8) -> isize { 0 } // ok!
460460
```
461461
"##,
462462

463-
// FIXME link this to the relevant turpl chapters for instilling fear of the
464-
// transmute gods in the user
463+
// isn't thrown anymore
465464
E0139: r##"
466465
There are various restrictions on transmuting between types in Rust; for example
467466
types being transmuted must have the same size. To apply all these restrictions,
@@ -470,11 +469,13 @@ parameters are involved, this cannot always be done.
470469
471470
So, for example, the following is not allowed:
472471
473-
```compile_fail
472+
```
473+
use std::mem::transmute;
474+
474475
struct Foo<T>(Vec<T>);
475476
476477
fn foo<T>(x: Vec<T>) {
477-
// we are transmuting between Vec<T> and Foo<T> here
478+
// we are transmuting between Vec<T> and Foo<F> here
478479
let y: Foo<T> = unsafe { transmute(x) };
479480
// do something with y
480481
}
@@ -542,7 +543,7 @@ A lang item was redefined.
542543
543544
Erroneous code example:
544545
545-
```compile_fail
546+
```compile_fail,E0152
546547
#![feature(lang_items)]
547548
548549
#[lang = "panic_fmt"]
@@ -567,7 +568,7 @@ E0229: r##"
567568
An associated type binding was done outside of the type parameter declaration
568569
and `where` clause. Erroneous code example:
569570
570-
```compile_fail
571+
```compile_fail,E0229
571572
pub trait Foo {
572573
type A;
573574
fn boo(&self) -> <Self as Foo>::A;
@@ -604,7 +605,7 @@ used.
604605
605606
These two examples illustrate the problem:
606607
607-
```compile_fail
608+
```compile_fail,E0261
608609
// error, use of undeclared lifetime name `'a`
609610
fn foo(x: &'a str) { }
610611
@@ -630,7 +631,7 @@ Declaring certain lifetime names in parameters is disallowed. For example,
630631
because the `'static` lifetime is a special built-in lifetime name denoting
631632
the lifetime of the entire program, this is an error:
632633
633-
```compile_fail
634+
```compile_fail,E0262
634635
// error, invalid lifetime parameter name `'static`
635636
fn foo<'static>(x: &'static str) { }
636637
```
@@ -640,7 +641,7 @@ E0263: r##"
640641
A lifetime name cannot be declared more than once in the same scope. For
641642
example:
642643
643-
```compile_fail
644+
```compile_fail,E0263
644645
// error, lifetime name `'a` declared twice in the same scope
645646
fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str) { }
646647
```
@@ -649,7 +650,7 @@ fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str) { }
649650
E0264: r##"
650651
An unknown external lang item was used. Erroneous code example:
651652
652-
```compile_fail
653+
```compile_fail,E0264
653654
#![feature(lang_items)]
654655
655656
extern "C" {
@@ -675,12 +676,9 @@ E0269: r##"
675676
Functions must eventually return a value of their return type. For example, in
676677
the following function:
677678
678-
```compile_fail
679-
fn foo(x: u8) -> u8 {
680-
if x > 0 {
681-
x // alternatively, `return x`
682-
}
683-
// nothing here
679+
```compile_fail,E0269
680+
fn abracada_FAIL() -> String {
681+
"this won't work".to_string();
684682
}
685683
```
686684
@@ -806,7 +804,7 @@ Examples follow.
806804
807805
Here is a basic example:
808806
809-
```compile_fail
807+
```compile_fail,E0271
810808
trait Trait { type AssociatedType; }
811809
812810
fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
@@ -947,6 +945,8 @@ position that needs that trait. For example, when the following code is
947945
compiled:
948946
949947
```compile_fail
948+
#![feature(on_unimplemented)]
949+
950950
fn foo<T: Index<u8>>(x: T){}
951951
952952
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
@@ -977,6 +977,8 @@ position that needs that trait. For example, when the following code is
977977
compiled:
978978
979979
```compile_fail
980+
#![feature(on_unimplemented)]
981+
980982
fn foo<T: Index<u8>>(x: T){}
981983
982984
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
@@ -1005,6 +1007,8 @@ position that needs that trait. For example, when the following code is
10051007
compiled:
10061008
10071009
```compile_fail
1010+
#![feature(on_unimplemented)]
1011+
10081012
fn foo<T: Index<u8>>(x: T){}
10091013
10101014
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
@@ -1028,7 +1032,7 @@ recursion in resolving some type bounds.
10281032
10291033
For example, in the following code:
10301034
1031-
```compile_fail
1035+
```compile_fail,E0275
10321036
trait Foo {}
10331037
10341038
struct Bar<T>(T);
@@ -1048,7 +1052,7 @@ E0276: r##"
10481052
This error occurs when a bound in an implementation of a trait does not match
10491053
the bounds specified in the original trait. For example:
10501054
1051-
```compile_fail
1055+
```compile_fail,E0276
10521056
trait Foo {
10531057
fn foo<T>(x: T);
10541058
}
@@ -1070,7 +1074,7 @@ E0277: r##"
10701074
You tried to use a type which doesn't implement some trait in a place which
10711075
expected that trait. Erroneous code example:
10721076
1073-
```compile_fail
1077+
```compile_fail,E0277
10741078
// here we declare the Foo trait with a bar method
10751079
trait Foo {
10761080
fn bar(&self);
@@ -1113,7 +1117,7 @@ fn main() {
11131117
11141118
Or in a generic context, an erroneous code example would look like:
11151119
1116-
```compile_fail
1120+
```compile_fail,E0277
11171121
fn some_func<T>(foo: T) {
11181122
println!("{:?}", foo); // error: the trait `core::fmt::Debug` is not
11191123
// implemented for the type `T`
@@ -1159,7 +1163,7 @@ You tried to supply a type which doesn't implement some trait in a location
11591163
which expected that trait. This error typically occurs when working with
11601164
`Fn`-based types. Erroneous code example:
11611165
1162-
```compile_fail
1166+
```compile_fail,E0281
11631167
fn foo<F: Fn()>(x: F) { }
11641168
11651169
fn main() {
@@ -1185,7 +1189,7 @@ parameter with a `FromIterator` bound, which for a `char` iterator is
11851189
implemented by `Vec` and `String` among others. Consider the following snippet
11861190
that reverses the characters of a string:
11871191
1188-
```compile_fail
1192+
```compile_fail,E0282
11891193
let x = "hello".chars().rev().collect();
11901194
```
11911195
@@ -1222,7 +1226,7 @@ occur when a type parameter of a struct or trait cannot be inferred. In that
12221226
case it is not always possible to use a type annotation, because all candidates
12231227
have the same return type. For instance:
12241228
1225-
```compile_fail
1229+
```compile_fail,E0282
12261230
struct Foo<T> {
12271231
num: T,
12281232
}
@@ -1248,7 +1252,7 @@ to unambiguously choose an implementation.
12481252
12491253
For example:
12501254
1251-
```compile_fail
1255+
```compile_fail,E0283
12521256
trait Generator {
12531257
fn create() -> u32;
12541258
}
@@ -1296,10 +1300,22 @@ fn main() {
12961300

12971301
E0296: r##"
12981302
This error indicates that the given recursion limit could not be parsed. Ensure
1299-
that the value provided is a positive integer between quotes, like so:
1303+
that the value provided is a positive integer between quotes.
1304+
1305+
Erroneous code example:
1306+
1307+
```compile_fail,E0296
1308+
#![recursion_limit]
1309+
1310+
fn main() {}
1311+
```
1312+
1313+
And a working example:
13001314
13011315
```
13021316
#![recursion_limit="1000"]
1317+
1318+
fn main() {}
13031319
```
13041320
"##,
13051321

@@ -1312,7 +1328,7 @@ variable.
13121328
13131329
For example:
13141330
1315-
```compile_fail
1331+
```compile_fail,E0308
13161332
let x: i32 = "I am not a number!";
13171333
// ~~~ ~~~~~~~~~~~~~~~~~~~~
13181334
// | |
@@ -1325,7 +1341,7 @@ let x: i32 = "I am not a number!";
13251341
Another situation in which this occurs is when you attempt to use the `try!`
13261342
macro inside a function that does not return a `Result<T, E>`:
13271343
1328-
```compile_fail
1344+
```compile_fail,E0308
13291345
use std::fs::File;
13301346
13311347
fn main() {
@@ -1353,7 +1369,7 @@ how long the data stored within them is guaranteed to be live. This lifetime
13531369
must be as long as the data needs to be alive, and missing the constraint that
13541370
denotes this will cause this error.
13551371
1356-
```compile_fail
1372+
```compile_fail,E0309
13571373
// This won't compile because T is not constrained, meaning the data
13581374
// stored in it is not guaranteed to last as long as the reference
13591375
struct Foo<'a, T> {
@@ -1376,7 +1392,7 @@ how long the data stored within them is guaranteed to be live. This lifetime
13761392
must be as long as the data needs to be alive, and missing the constraint that
13771393
denotes this will cause this error.
13781394
1379-
```compile_fail
1395+
```compile_fail,E0310
13801396
// This won't compile because T is not constrained to the static lifetime
13811397
// the reference needs
13821398
struct Foo<T> {
@@ -1430,7 +1446,7 @@ references (with a maximum lifetime of `'a`).
14301446
E0452: r##"
14311447
An invalid lint attribute has been given. Erroneous code example:
14321448
1433-
```compile_fail
1449+
```compile_fail,E0452
14341450
#![allow(foo = "")] // error: malformed lint attribute
14351451
```
14361452
@@ -1450,7 +1466,7 @@ attribute on an enclosing scope, or on the command line with the `-F` option.
14501466
14511467
Example of erroneous code:
14521468
1453-
```compile_fail
1469+
```compile_fail,E0453
14541470
#![forbid(non_snake_case)]
14551471
14561472
#[allow(non_snake_case)]
@@ -1492,7 +1508,7 @@ fn main() {
14921508
E0496: r##"
14931509
A lifetime name is shadowing another lifetime name. Erroneous code example:
14941510
1495-
```compile_fail
1511+
```compile_fail,E0496
14961512
struct Foo<'a> {
14971513
a: &'a i32,
14981514
}
@@ -1539,7 +1555,7 @@ E0512: r##"
15391555
Transmute with two differently sized types was attempted. Erroneous code
15401556
example:
15411557
1542-
```compile_fail
1558+
```compile_fail,E0512
15431559
fn takes_u8(_: u8) {}
15441560
15451561
fn main() {
@@ -1567,7 +1583,7 @@ unsupported item.
15671583
15681584
Examples of erroneous code:
15691585
1570-
```compile_fail
1586+
```compile_fail,E0517
15711587
#[repr(C)]
15721588
type Foo = u8;
15731589
@@ -1615,7 +1631,7 @@ on something other than a function or method.
16151631
16161632
Examples of erroneous code:
16171633
1618-
```compile_fail
1634+
```compile_fail,E0518
16191635
#[inline(always)]
16201636
struct Foo;
16211637
@@ -1642,7 +1658,7 @@ how the compiler behaves, as well as special functions that may be automatically
16421658
invoked (such as the handler for out-of-bounds accesses when indexing a slice).
16431659
Erroneous code example:
16441660
1645-
```compile_fail
1661+
```compile_fail,E0522
16461662
#![feature(lang_items)]
16471663
16481664
#[lang = "cookie"]

0 commit comments

Comments
 (0)