1 syntax::register_diagnostics! {
3 #### Note: this error code is no longer emitted by the compiler.
5 Constants can only be initialized by a constant value or, in a future
6 version of Rust, a call to a const function. This error indicates the use
7 of a path (like a::b, or x) denoting something other than one of these
10 Erroneous code example:
13 const FOO: i32 = { let x = 0; x }; // 'x' isn't a constant nor a function!
16 To avoid it, you have to replace the non-constant value:
19 const FOO: i32 = { const X : i32 = 0; X };
21 const FOO2: i32 = { 0 }; // but brackets are useless here
26 You declared a pattern as an argument in a foreign function declaration.
28 Erroneous code example:
32 fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
33 // function declarations
37 Please replace the pattern argument with a regular one. Example:
46 fn foo(s: SomeStruct); // ok!
54 fn foo(a: (u32, u32)); // ok!
59 // This shouldn't really ever trigger since the repeated value error comes first
61 A binary can only have one entry point, and by default that entry point is the
62 function `main()`. If there are multiple such functions, please rename one.
64 Erroneous code example:
80 More than one function was declared with the `#[main]` attribute.
82 Erroneous code example:
91 fn f() {} // error: multiple functions with a `#[main]` attribute
94 This error indicates that the compiler found multiple functions with the
95 `#[main]` attribute. This is an error because there must be a unique entry
96 point into a Rust program. Example:
107 More than one function was declared with the `#[start]` attribute.
109 Erroneous code example:
111 ```compile_fail,E0138
115 fn foo(argc: isize, argv: *const *const u8) -> isize {}
118 fn f(argc: isize, argv: *const *const u8) -> isize {}
119 // error: multiple 'start' functions
122 This error indicates that the compiler found multiple functions with the
123 `#[start]` attribute. This is an error because there must be a unique entry
124 point into a Rust program. Example:
130 fn foo(argc: isize, argv: *const *const u8) -> isize { 0 } // ok!
135 Inherent implementations (one that do not implement a trait but provide
136 methods associated with a type) are always safe because they are not
137 implementing an unsafe trait. Removing the `unsafe` keyword from the inherent
138 implementation will resolve this error.
140 ```compile_fail,E0197
143 // this will cause this error
145 // converting it to this will fix it
151 A negative implementation is one that excludes a type from implementing a
152 particular trait. Not being able to use a trait is always a safe operation,
153 so negative implementations are always safe and never need to be marked as
157 #![feature(optin_builtin_traits)]
161 // unsafe is unnecessary
162 unsafe impl !Clone for Foo { }
167 ```ignore (ignore auto_trait future compatibility warning)
168 #![feature(optin_builtin_traits)]
172 auto trait Enterprise {}
174 impl !Enterprise for Foo { }
177 Please note that negative impls are only allowed for auto traits.
181 This error indicates the use of a loop keyword (`break` or `continue`) inside a
182 closure but outside of any loop. Erroneous code example:
184 ```compile_fail,E0267
185 let w = || { break; }; // error: `break` inside of a closure
188 `break` and `continue` keywords can be used as normal inside closures as long as
189 they are also contained within a loop. To halt the execution of a closure you
190 should instead use a return statement. Example:
204 This error indicates the use of a loop keyword (`break` or `continue`) outside
205 of a loop. Without a loop to break out of or continue in, no sensible action can
206 be taken. Erroneous code example:
208 ```compile_fail,E0268
210 break; // error: `break` outside of a loop
214 Please verify that you are using `break` and `continue` only in loops. Example:
226 Trait methods cannot be declared `const` by design. For more information, see
229 [RFC 911]: https://github.com/rust-lang/rfcs/pull/911
233 Auto traits cannot have methods or associated items.
234 For more information see the [opt-in builtin traits RFC][RFC 19].
236 [RFC 19]: https://github.com/rust-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md
240 A visibility qualifier was used when it was unnecessary. Erroneous code
243 ```compile_fail,E0449
250 pub impl Bar {} // error: unnecessary visibility qualifier
252 pub impl Foo for Bar { // error: unnecessary visibility qualifier
253 pub fn foo() {} // error: unnecessary visibility qualifier
257 To fix this error, please remove the visibility qualifier when it is not
267 // Directly implemented methods share the visibility of the type itself,
268 // so `pub` is unnecessary here
271 // Trait methods share the visibility of the trait, so `pub` is
272 // unnecessary in either case
280 Transmute with two differently sized types was attempted. Erroneous code
283 ```compile_fail,E0512
284 fn takes_u8(_: u8) {}
287 unsafe { takes_u8(::std::mem::transmute(0u16)); }
288 // error: cannot transmute between types of different sizes,
289 // or dependently-sized types
293 Please use types with same size or use the expected type directly. Example:
296 fn takes_u8(_: u8) {}
299 unsafe { takes_u8(::std::mem::transmute(0i8)); } // ok!
301 unsafe { takes_u8(0u8); } // ok!
307 A non-ident or non-wildcard pattern has been used as a parameter of a function
310 Erroneous code example:
312 ```compile_fail,E0561
313 type A1 = fn(mut param: u8); // error!
314 type A2 = fn(¶m: u32); // error!
317 When using an alias over a function type, you cannot e.g. denote a parameter as
320 To fix the issue, remove patterns (`_` is allowed though). Example:
323 type A1 = fn(param: u8); // ok!
324 type A2 = fn(_: u32); // ok!
327 You can also omit the parameter name:
330 type A3 = fn(i16); // ok!
335 Generics have been used on an auto trait.
337 Erroneous code example:
339 ```compile_fail,E0567
340 #![feature(optin_builtin_traits)]
342 auto trait Generic<T> {} // error!
347 Since an auto trait is implemented on all existing types, the
348 compiler would not be able to infer the types of the trait's generic
351 To fix this issue, just remove the generics:
354 #![feature(optin_builtin_traits)]
356 auto trait Generic {} // ok!
363 A `break` statement with an argument appeared in a non-`loop` loop.
365 Example of erroneous code:
367 ```compile_fail,E0571
369 # fn satisfied(n: usize) -> bool { n % 23 == 0 }
370 let result = while true {
372 break 2*i; // error: `break` with value from a `while` loop
378 The `break` statement can take an argument (which will be the value of the loop
379 expression if the `break` statement is executed) in `loop` loops, but not
380 `for`, `while`, or `while let` loops.
382 Make sure `break value;` statements only occur in `loop` loops:
386 # fn satisfied(n: usize) -> bool { n % 23 == 0 }
387 let result = loop { // ok!
397 `break` or `continue` must include a label when used in the condition of a
400 Example of erroneous code:
406 To fix this, add a label specifying which loop is being broken out of:
408 'foo: while break 'foo {}
413 Per [RFC 401][rfc401], if you have a function declaration `foo`:
416 // For the purposes of this explanation, all of these
417 // different kinds of `fn` declarations are equivalent:
419 fn foo(x: S) { /* ... */ }
420 # #[cfg(for_demonstration_only)]
421 extern "C" { fn foo(x: S); }
422 # #[cfg(for_demonstration_only)]
423 impl S { fn foo(self) { /* ... */ } }
426 the type of `foo` is **not** `fn(S)`, as one might expect.
427 Rather, it is a unique, zero-sized marker type written here as `typeof(foo)`.
428 However, `typeof(foo)` can be _coerced_ to a function pointer `fn(S)`,
429 so you rarely notice this:
434 let x: fn(S) = foo; // OK, coerces
437 The reason that this matter is that the type `fn(S)` is not specific to
438 any particular function: it's a function _pointer_. So calling `x()` results
439 in a virtual call, whereas `foo()` is statically dispatched, because the type
440 of `foo` tells us precisely what function is being called.
442 As noted above, coercions mean that most code doesn't have to be
443 concerned with this distinction. However, you can tell the difference
444 when using **transmute** to convert a fn item into a fn pointer.
446 This is sometimes done as part of an FFI:
448 ```compile_fail,E0591
449 extern "C" fn foo(userdata: Box<i32>) {
453 # fn callback(_: extern "C" fn(*mut i32)) {}
454 # use std::mem::transmute;
456 let f: extern "C" fn(*mut i32) = transmute(foo);
461 Here, transmute is being used to convert the types of the fn arguments.
462 This pattern is incorrect because, because the type of `foo` is a function
463 **item** (`typeof(foo)`), which is zero-sized, and the target type (`fn()`)
464 is a function pointer, which is not zero-sized.
465 This pattern should be rewritten. There are a few possible ways to do this:
467 - change the original fn declaration to match the expected signature,
468 and do the cast in the fn body (the preferred option)
469 - cast the fn item fo a fn pointer before calling transmute, as shown here:
472 # extern "C" fn foo(_: Box<i32>) {}
473 # use std::mem::transmute;
475 let f: extern "C" fn(*mut i32) = transmute(foo as extern "C" fn(_));
476 let f: extern "C" fn(*mut i32) = transmute(foo as usize); // works too
480 The same applies to transmutes to `*mut fn()`, which were observed in practice.
481 Note though that use of this type is generally incorrect.
482 The intention is typically to describe a function pointer, but just `fn()`
483 alone suffices for that. `*mut fn()` is a pointer to a fn pointer.
484 (Since these values are typically just passed to C code, however, this rarely
485 makes a difference in practice.)
487 [rfc401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
491 No `main` function was found in a binary crate. To fix this error, add a
492 `main` function. For example:
496 // Your program will start here.
497 println!("Hello world!");
501 If you don't know the basics of Rust, you can go look to the Rust Book to get
502 started: https://doc.rust-lang.org/book/
506 Trait methods currently cannot take patterns as arguments.
508 Example of erroneous code:
510 ```compile_fail,E0642
512 fn foo((x, y): (i32, i32)); // error: patterns aren't allowed
517 You can instead use a single name for the argument:
521 fn foo(x_and_y: (i32, i32)); // ok!
527 A `break` statement without a label appeared inside a labeled block.
529 Example of erroneous code:
531 ```compile_fail,E0695
532 # #![feature(label_break_value)]
540 Make sure to always label the `break`:
543 # #![feature(label_break_value)]
551 Or if you want to `break` the labeled block:
554 # #![feature(label_break_value)]
565 Rust 2015 does not permit the use of `async fn`.
567 Example of erroneous code:
569 ```compile_fail,E0670
573 Switch to the Rust 2018 edition to use `async fn`.
577 E0226, // only a single explicit lifetime bound is permitted
578 E0472, // asm! is unsupported on this target
579 E0568, // auto traits can not have super traits
580 E0666, // nested `impl Trait` is illegal
581 E0667, // `impl Trait` in projections
582 E0696, // `continue` pointing to a labeled block
583 E0706, // `async fn` in trait