2016-01-15 13:16:54 +01:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
|
|
|
#![allow(non_snake_case)]
|
|
|
|
|
|
|
|
register_long_diagnostics! {
|
2016-07-20 00:02:56 +03:00
|
|
|
/*
|
2016-01-21 10:52:37 +01:00
|
|
|
E0014: r##"
|
|
|
|
Constants can only be initialized by a constant value or, in a future
|
|
|
|
version of Rust, a call to a const function. This error indicates the use
|
|
|
|
of a path (like a::b, or x) denoting something other than one of these
|
2016-02-07 13:02:52 +01:00
|
|
|
allowed items. Erroneous code xample:
|
2016-01-21 10:52:37 +01:00
|
|
|
|
2016-02-07 13:02:52 +01:00
|
|
|
```compile_fail
|
2016-01-21 10:52:37 +01:00
|
|
|
const FOO: i32 = { let x = 0; x }; // 'x' isn't a constant nor a function!
|
|
|
|
```
|
|
|
|
|
|
|
|
To avoid it, you have to replace the non-constant value:
|
|
|
|
|
|
|
|
```
|
|
|
|
const FOO: i32 = { const X : i32 = 0; X };
|
|
|
|
// or even:
|
2016-02-07 13:02:52 +01:00
|
|
|
const FOO2: i32 = { 0 }; // but brackets are useless here
|
2016-01-21 10:52:37 +01:00
|
|
|
```
|
|
|
|
"##,
|
2016-07-20 00:02:56 +03:00
|
|
|
*/
|
2016-01-21 10:52:37 +01:00
|
|
|
E0030: r##"
|
|
|
|
When matching against a range, the compiler verifies that the range is
|
|
|
|
non-empty. Range patterns include both end-points, so this is equivalent to
|
|
|
|
requiring the start of the range to be less than or equal to the end of the
|
|
|
|
range.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
2016-02-07 13:02:52 +01:00
|
|
|
```compile_fail
|
2016-01-21 10:52:37 +01:00
|
|
|
match 5u32 {
|
|
|
|
// This range is ok, albeit pointless.
|
2016-02-07 13:02:52 +01:00
|
|
|
1 ... 1 => {}
|
2016-01-21 10:52:37 +01:00
|
|
|
// This range is empty, and the compiler can tell.
|
2016-02-07 13:02:52 +01:00
|
|
|
1000 ... 5 => {}
|
2016-01-21 10:52:37 +01:00
|
|
|
}
|
|
|
|
```
|
|
|
|
"##,
|
|
|
|
|
2016-07-17 00:15:15 +03:00
|
|
|
E0130: r##"
|
|
|
|
You declared a pattern as an argument in a foreign function declaration.
|
|
|
|
Erroneous code example:
|
|
|
|
|
|
|
|
```compile_fail
|
|
|
|
extern {
|
|
|
|
fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
|
|
|
|
// function declarations
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Please replace the pattern argument with a regular one. Example:
|
|
|
|
|
|
|
|
```
|
|
|
|
struct SomeStruct {
|
|
|
|
a: u32,
|
|
|
|
b: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
extern {
|
|
|
|
fn foo(s: SomeStruct); // ok!
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Or:
|
|
|
|
|
|
|
|
```
|
|
|
|
extern {
|
|
|
|
fn foo(a: (u32, u32)); // ok!
|
|
|
|
}
|
|
|
|
```
|
|
|
|
"##,
|
|
|
|
|
2016-01-21 10:52:37 +01:00
|
|
|
E0265: r##"
|
|
|
|
This error indicates that a static or constant references itself.
|
|
|
|
All statics and constants need to resolve to a value in an acyclic manner.
|
|
|
|
|
|
|
|
For example, neither of the following can be sensibly compiled:
|
|
|
|
|
2016-08-05 13:17:39 +02:00
|
|
|
```compile_fail,E0265
|
2016-01-21 10:52:37 +01:00
|
|
|
const X: u32 = X;
|
|
|
|
```
|
|
|
|
|
2016-08-05 13:17:39 +02:00
|
|
|
```compile_fail,E0265
|
2016-01-21 10:52:37 +01:00
|
|
|
const X: u32 = Y;
|
|
|
|
const Y: u32 = X;
|
|
|
|
```
|
|
|
|
"##,
|
|
|
|
|
|
|
|
E0267: r##"
|
|
|
|
This error indicates the use of a loop keyword (`break` or `continue`) inside a
|
|
|
|
closure but outside of any loop. Erroneous code example:
|
|
|
|
|
2016-08-05 13:17:39 +02:00
|
|
|
```compile_fail,E0267
|
2016-01-21 10:52:37 +01:00
|
|
|
let w = || { break; }; // error: `break` inside of a closure
|
|
|
|
```
|
|
|
|
|
|
|
|
`break` and `continue` keywords can be used as normal inside closures as long as
|
|
|
|
they are also contained within a loop. To halt the execution of a closure you
|
|
|
|
should instead use a return statement. Example:
|
|
|
|
|
|
|
|
```
|
|
|
|
let w = || {
|
|
|
|
for _ in 0..10 {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
w();
|
|
|
|
```
|
|
|
|
"##,
|
|
|
|
|
|
|
|
E0268: r##"
|
|
|
|
This error indicates the use of a loop keyword (`break` or `continue`) outside
|
|
|
|
of a loop. Without a loop to break out of or continue in, no sensible action can
|
|
|
|
be taken. Erroneous code example:
|
|
|
|
|
2016-08-05 13:17:39 +02:00
|
|
|
```compile_fail,E0268
|
2016-01-21 10:52:37 +01:00
|
|
|
fn some_func() {
|
|
|
|
break; // error: `break` outside of loop
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Please verify that you are using `break` and `continue` only in loops. Example:
|
|
|
|
|
|
|
|
```
|
|
|
|
fn some_func() {
|
|
|
|
for _ in 0..10 {
|
|
|
|
break; // ok!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
"##,
|
|
|
|
|
2016-08-07 14:33:35 -07:00
|
|
|
E0379: r##"
|
|
|
|
Trait methods cannot be declared `const` by design. For more information, see
|
|
|
|
[RFC 911].
|
|
|
|
|
|
|
|
[RFC 911]: https://github.com/rust-lang/rfcs/pull/911
|
|
|
|
"##,
|
|
|
|
|
2016-05-22 18:07:28 +03:00
|
|
|
E0449: r##"
|
|
|
|
A visibility qualifier was used when it was unnecessary. Erroneous code
|
|
|
|
examples:
|
|
|
|
|
|
|
|
```compile_fail
|
|
|
|
struct Bar;
|
|
|
|
|
|
|
|
trait Foo {
|
|
|
|
fn foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub impl Bar {} // error: unnecessary visibility qualifier
|
|
|
|
|
|
|
|
pub impl Foo for Bar { // error: unnecessary visibility qualifier
|
|
|
|
pub fn foo() {} // error: unnecessary visibility qualifier
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
To fix this error, please remove the visibility qualifier when it is not
|
|
|
|
required. Example:
|
|
|
|
|
|
|
|
```ignore
|
|
|
|
struct Bar;
|
|
|
|
|
|
|
|
trait Foo {
|
|
|
|
fn foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Directly implemented methods share the visibility of the type itself,
|
|
|
|
// so `pub` is unnecessary here
|
|
|
|
impl Bar {}
|
|
|
|
|
|
|
|
// Trait methods share the visibility of the trait, so `pub` is
|
|
|
|
// unnecessary in either case
|
|
|
|
pub impl Foo for Bar {
|
|
|
|
pub fn foo() {}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
"##,
|
|
|
|
|
2017-01-10 22:13:53 +01:00
|
|
|
|
|
|
|
E0579: r##"
|
|
|
|
When matching against an exclusive range, the compiler verifies that the range
|
|
|
|
is non-empty. Exclusive range patterns include the start point but not the end
|
|
|
|
point, so this is equivalent to requiring the start of the range to be less
|
|
|
|
than the end of the range.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
```compile_fail
|
|
|
|
match 5u32 {
|
|
|
|
// This range is ok, albeit pointless.
|
|
|
|
1 .. 2 => {}
|
|
|
|
// This range is empty, and the compiler can tell.
|
|
|
|
5 .. 5 => {}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
"##,
|
2017-02-15 23:28:59 -08:00
|
|
|
|
2017-02-22 18:10:37 -08:00
|
|
|
E0590: r##"
|
2017-02-15 23:28:59 -08:00
|
|
|
`break` or `continue` must include a label when used in the condition of a
|
|
|
|
`while` loop.
|
|
|
|
|
|
|
|
Example of erroneous code:
|
|
|
|
|
|
|
|
```compile_fail
|
|
|
|
while break {}
|
|
|
|
```
|
|
|
|
|
|
|
|
To fix this, add a label specifying which loop is being broken out of:
|
|
|
|
```
|
|
|
|
`foo: while break `foo {}
|
|
|
|
```
|
|
|
|
"##
|
2016-01-15 13:16:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
register_diagnostics! {
|
2017-01-24 17:17:06 +02:00
|
|
|
E0226, // only a single explicit lifetime bound is permitted
|
2016-01-15 13:16:54 +01:00
|
|
|
E0472, // asm! is unsupported on this target
|
2016-07-17 00:15:15 +03:00
|
|
|
E0561, // patterns aren't allowed in function pointer types
|
Implement the `loop_break_value` feature.
This implements RFC 1624, tracking issue #37339.
- `FnCtxt` (in typeck) gets a stack of `LoopCtxt`s, which store the
currently deduced type of that loop, the desired type, and a list of
break expressions currently seen. `loop` loops get a fresh type
variable as their initial type (this logic is stolen from that for
arrays). `while` loops get `()`.
- `break {expr}` looks up the broken loop, and unifies the type of
`expr` with the type of the loop.
- `break` with no expr unifies the loop's type with `()`.
- When building MIR, `loop` loops no longer construct a `()` value at
termination of the loop; rather, the `break` expression assigns the
result of the loop. `while` loops are unchanged.
- `break` respects contexts in which expressions may not end with braced
blocks. That is, `while break { break-value } { while-body }` is
illegal; this preserves backwards compatibility.
- The RFC did not make it clear, but I chose to make `break ()` inside
of a `while` loop illegal, just in case we wanted to do anything with
that design space in the future.
This is my first time dealing with this part of rustc so I'm sure
there's plenty of problems to pick on here ^_^
2016-10-29 15:15:06 -07:00
|
|
|
E0571, // `break` with a value in a non-`loop`-loop
|
2016-01-15 13:16:54 +01:00
|
|
|
}
|