Constant rustc::DIAGNOSTICS [] [src]

pub const DIAGNOSTICS: [(&'static str, &'static str); 50] = [("E0020",
  "\nThis error indicates that an attempt was made to divide by zero (or take the\nremainder of a zero divisor) in a static or constant expression. Erroneous\ncode example:\n\n```compile_fail\n#[deny(const_err)]\n\nconst X: i32 = 42 / 0;\n// error: attempt to divide by zero in a constant expression\n```\n"),
  "\nTrait objects like `Box<Trait>` can only be constructed when certain\nrequirements are satisfied by the trait in question.\n\nTrait objects are a form of dynamic dispatch and use a dynamically sized type\nfor the inner type. So, for a given trait `Trait`, when `Trait` is treated as a\ntype, as in `Box<Trait>`, the inner type is \'unsized\'. In such cases the boxed\npointer is a \'fat pointer\' that contains an extra pointer to a table of methods\n(among other things) for dynamic dispatch. This design mandates some\nrestrictions on the types of traits that are allowed to be used in trait\nobjects, which are collectively termed as \'object safety\' rules.\n\nAttempting to create a trait object for a non object-safe trait will trigger\nthis error.\n\nThere are various rules:\n\n### The trait cannot require `Self: Sized`\n\nWhen `Trait` is treated as a type, the type does not implement the special\n`Sized` trait, because the type does not have a known size at compile time and\ncan only be accessed behind a pointer. Thus, if we have a trait like the\nfollowing:\n\n```\ntrait Foo where Self: Sized {\n\n}\n```\n\nWe cannot create an object of type `Box<Foo>` or `&Foo` since in this case\n`Self` would not be `Sized`.\n\nGenerally, `Self : Sized` is used to indicate that the trait should not be used\nas a trait object. If the trait comes from your own crate, consider removing\nthis restriction.\n\n### Method references the `Self` type in its arguments or return type\n\nThis happens when a trait has a method like the following:\n\n```\ntrait Trait {\n    fn foo(&self) -> Self;\n}\n\nimpl Trait for String {\n    fn foo(&self) -> Self {\n        \"hi\".to_owned()\n    }\n}\n\nimpl Trait for u8 {\n    fn foo(&self) -> Self {\n        1\n    }\n}\n```\n\n(Note that `&self` and `&mut self` are okay, it\'s additional `Self` types which\ncause this problem.)\n\nIn such a case, the compiler cannot predict the return type of `foo()` in a\nsituation like the following:\n\n```compile_fail\ntrait Trait {\n    fn foo(&self) -> Self;\n}\n\nfn call_foo(x: Box<Trait>) {\n    let y =; // What type is y?\n    // ...\n}\n```\n\nIf only some methods aren\'t object-safe, you can add a `where Self: Sized` bound\non them to mark them as explicitly unavailable to trait objects. The\nfunctionality will still be available to all other implementers, including\n`Box<Trait>` which is itself sized (assuming you `impl Trait for Box<Trait>`).\n\n```\ntrait Trait {\n    fn foo(&self) -> Self where Self: Sized;\n    // more functions\n}\n```\n\nNow, `foo()` can no longer be called on a trait object, but you will now be\nallowed to make a trait object, and that will be able to call any object-safe\nmethods. With such a bound, one can still call `foo()` on types implementing\nthat trait that aren\'t behind trait objects.\n\n### Method has generic type parameters\n\nAs mentioned before, trait objects contain pointers to method tables. So, if we\nhave:\n\n```\ntrait Trait {\n    fn foo(&self);\n}\n\nimpl Trait for String {\n    fn foo(&self) {\n        // implementation 1\n    }\n}\n\nimpl Trait for u8 {\n    fn foo(&self) {\n        // implementation 2\n    }\n}\n// ...\n```\n\nAt compile time each implementation of `Trait` will produce a table containing\nthe various methods (and other items) related to the implementation.\n\nThis works fine, but when the method gains generic parameters, we can have a\nproblem.\n\nUsually, generic parameters get _monomorphized_. For example, if I have\n\n```\nfn foo<T>(x: T) {\n    // ...\n}\n```\n\nThe machine code for `foo::<u8>()`, `foo::<bool>()`, `foo::<String>()`, or any\nother type substitution is different. Hence the compiler generates the\nimplementation on-demand. If you call `foo()` with a `bool` parameter, the\ncompiler will only generate code for `foo::<bool>()`. When we have additional\ntype parameters, the number of monomorphized implementations the compiler\ngenerates does not grow drastically, since the compiler will only generate an\nimplementation if the function is called with unparametrized substitutions\n(i.e., substitutions where none of the substituted types are themselves\nparametrized).\n\nHowever, with trait objects we have to make a table containing _every_ object\nthat implements the trait. Now, if it has type parameters, we need to add\nimplementations for every type that implements the trait, and there could\ntheoretically be an infinite number of types.\n\nFor example, with:\n\n```\ntrait Trait {\n    fn foo<T>(&self, on: T);\n    // more methods\n}\n\nimpl Trait for String {\n    fn foo<T>(&self, on: T) {\n        // implementation 1\n    }\n}\n\nimpl Trait for u8 {\n    fn foo<T>(&self, on: T) {\n        // implementation 2\n    }\n}\n\n// 8 more implementations\n```\n\nNow, if we have the following code:\n\n```compile_fail,E0038\n# trait Trait { fn foo<T>(&self, on: T); }\n# impl Trait for String { fn foo<T>(&self, on: T) {} }\n# impl Trait for u8 { fn foo<T>(&self, on: T) {} }\n# impl Trait for bool { fn foo<T>(&self, on: T) {} }\n# // etc.\nfn call_foo(thing: Box<Trait>) {\n; // this could be any one of the 8 types above\n;\n\"hello\");\n}\n```\n\nWe don\'t just need to create a table of all implementations of all methods of\n`Trait`, we need to create such a table, for each different type fed to\n`foo()`. In this case this turns out to be (10 types implementing `Trait`)*(3\ntypes being fed to `foo()`) = 30 implementations!\n\nWith real world traits these numbers can grow drastically.\n\nTo fix this, it is suggested to use a `where Self: Sized` bound similar to the\nfix for the sub-error above if you do not intend to call the method with type\nparameters:\n\n```\ntrait Trait {\n    fn foo<T>(&self, on: T) where Self: Sized;\n    // more methods\n}\n```\n\nIf this is not an option, consider replacing the type parameter with another\ntrait object (e.g. if `T: OtherTrait`, use `on: Box<OtherTrait>`). If the number\nof types you intend to feed to this method is limited, consider manually listing\nout the methods of different types.\n\n### Method has no receiver\n\nMethods that do not take a `self` parameter can\'t be called since there won\'t be\na way to get a pointer to the method table for them.\n\n```\ntrait Foo {\n    fn foo() -> u8;\n}\n```\n\nThis could be called as `<Foo as Foo>::foo()`, which would not be able to pick\nan implementation.\n\nAdding a `Self: Sized` bound to these methods will generally make this compile.\n\n```\ntrait Foo {\n    fn foo() -> u8 where Self: Sized;\n}\n```\n\n### The trait cannot use `Self` as a type parameter in the supertrait listing\n\nThis is similar to the second sub-error, but subtler. It happens in situations\nlike the following:\n\n```compile_fail\ntrait Super<A> {}\n\ntrait Trait: Super<Self> {\n}\n\nstruct Foo;\n\nimpl Super<Foo> for Foo{}\n\nimpl Trait for Foo {}\n```\n\nHere, the supertrait might have methods as follows:\n\n```\ntrait Super<A> {\n    fn get_a(&self) -> A; // note that this is object safe!\n}\n```\n\nIf the trait `Foo` was deriving from something like `Super<String>` or\n`Super<T>` (where `Foo` itself is `Foo<T>`), this is okay, because given a type\n`get_a()` will definitely return an object of that type.\n\nHowever, if it derives from `Super<Self>`, even though `Super` is object safe,\nthe method `get_a()` would return an object of unknown type when called on the\nfunction. `Self` type parameters let us make object safe traits no longer safe,\nso they are forbidden when specifying supertraits.\n\nThere\'s no easy fix for this, generally code will need to be refactored so that\nyou no longer need to derive from `Super<Self>`.\n"),
  "\nWhen defining a recursive struct or enum, any use of the type being defined\nfrom inside the definition must occur behind a pointer (like `Box` or `&`).\nThis is because structs and enums must have a well-defined size, and without\nthe pointer, the size of the type would need to be unbounded.\n\nConsider the following erroneous definition of a type for a list of bytes:\n\n```compile_fail,E0072\n// error, invalid recursive struct type\nstruct ListNode {\n    head: u8,\n    tail: Option<ListNode>,\n}\n```\n\nThis type cannot have a well-defined size, because it needs to be arbitrarily\nlarge (since we would be able to nest `ListNode`s to any depth). Specifically,\n\n```plain\nsize of `ListNode` = 1 byte for `head`\n                   + 1 byte for the discriminant of the `Option`\n                   + size of `ListNode`\n```\n\nOne way to fix this is by wrapping `ListNode` in a `Box`, like so:\n\n```\nstruct ListNode {\n    head: u8,\n    tail: Option<Box<ListNode>>,\n}\n```\n\nThis works because `Box` is a pointer, so its size is well-known.\n"),
  "\nThis error indicates that the compiler was unable to sensibly evaluate an\nconstant expression that had to be evaluated. Attempting to divide by 0\nor causing integer overflow are two ways to induce this error. For example:\n\n```compile_fail,E0080\nenum Enum {\n    X = (1 << 500),\n    Y = (1 / 0)\n}\n```\n\nEnsure that the expressions given can be evaluated as the desired integer type.\nSee the FFI section of the Reference for more information about using a custom\ninteger type:\n\n\n"),
  "\nThis error indicates that a lifetime is missing from a type. If it is an error\ninside a function signature, the problem may be with failing to adhere to the\nlifetime elision rules (see below).\n\nHere are some simple examples of where you\'ll run into this error:\n\n```compile_fail,E0106\nstruct Foo { x: &bool }        // error\nstruct Foo<\'a> { x: &\'a bool } // correct\n\nstruct Bar { x: Foo }\n               ^^^ expected lifetime parameter\nstruct Bar<\'a> { x: Foo<\'a> } // correct\n\nenum Bar { A(u8), B(&bool), }        // error\nenum Bar<\'a> { A(u8), B(&\'a bool), } // correct\n\ntype MyStr = &str;        // error\ntype MyStr<\'a> = &\'a str; // correct\n```\n\nLifetime elision is a special, limited kind of inference for lifetimes in\nfunction signatures which allows you to leave out lifetimes in certain cases.\nFor more background on lifetime elision see [the book][book-le].\n\nThe lifetime elision rules require that any function signature with an elided\noutput lifetime must either have\n\n - exactly one input lifetime\n - or, multiple input lifetimes, but the function must also be a method with a\n   `&self` or `&mut self` receiver\n\nIn the first case, the output lifetime is inferred to be the same as the unique\ninput lifetime. In the second case, the lifetime is instead inferred to be the\nsame as the lifetime on `&self` or `&mut self`.\n\nHere are some examples of elision errors:\n\n```compile_fail,E0106\n// error, no input lifetimes\nfn foo() -> &str { }\n\n// error, `x` and `y` have distinct lifetimes inferred\nfn bar(x: &str, y: &str) -> &str { }\n\n// error, `y`\'s lifetime is inferred to be distinct from `x`\'s\nfn baz<\'a>(x: &\'a str, y: &str) -> &str { }\n```\n\nLifetime elision in implementation headers was part of the lifetime elision\nRFC. It is, however, [currently unimplemented][iss15872].\n\n[book-le]:\n[iss15872]:\n"),
  "\nThere are conflicting trait implementations for the same type.\nExample of erroneous code:\n\n```compile_fail,E0119\ntrait MyTrait {\n    fn get(&self) -> usize;\n}\n\nimpl<T> MyTrait for T {\n    fn get(&self) -> usize { 0 }\n}\n\nstruct Foo {\n    value: usize\n}\n\nimpl MyTrait for Foo { // error: conflicting implementations of trait\n                       //        `MyTrait` for type `Foo`\n    fn get(&self) -> usize { self.value }\n}\n```\n\nWhen looking for the implementation for the trait, the compiler finds\nboth the `impl<T> MyTrait for T` where T is all types and the `impl\nMyTrait for Foo`. Since a trait cannot be implemented multiple times,\nthis is an error. So, when you write:\n\n```\ntrait MyTrait {\n    fn get(&self) -> usize;\n}\n\nimpl<T> MyTrait for T {\n    fn get(&self) -> usize { 0 }\n}\n```\n\nThis makes the trait implemented on all types in the scope. So if you\ntry to implement it on another one after that, the implementations will\nconflict. Example:\n\n```\ntrait MyTrait {\n    fn get(&self) -> usize;\n}\n\nimpl<T> MyTrait for T {\n    fn get(&self) -> usize { 0 }\n}\n\nstruct Foo;\n\nfn main() {\n    let f = Foo;\n\n    f.get(); // the trait is implemented so we can use it\n}\n```\n"),
  "\nA binary can only have one entry point, and by default that entry point is the\nfunction `main()`. If there are multiple such functions, please rename one.\n"),
  "\nMore than one function was declared with the `#[main]` attribute.\n\nErroneous code example:\n\n```compile_fail,E0137\n#![feature(main)]\n\n#[main]\nfn foo() {}\n\n#[main]\nfn f() {} // error: multiple functions with a #[main] attribute\n```\n\nThis error indicates that the compiler found multiple functions with the\n`#[main]` attribute. This is an error because there must be a unique entry\npoint into a Rust program. Example:\n\n```\n#![feature(main)]\n\n#[main]\nfn f() {} // ok!\n```\n"),
  "\nMore than one function was declared with the `#[start]` attribute.\n\nErroneous code example:\n\n```compile_fail,E0138\n#![feature(start)]\n\n#[start]\nfn foo(argc: isize, argv: *const *const u8) -> isize {}\n\n#[start]\nfn f(argc: isize, argv: *const *const u8) -> isize {}\n// error: multiple \'start\' functions\n```\n\nThis error indicates that the compiler found multiple functions with the\n`#[start]` attribute. This is an error because there must be a unique entry\npoint into a Rust program. Example:\n\n```\n#![feature(start)]\n\n#[start]\nfn foo(argc: isize, argv: *const *const u8) -> isize { 0 } // ok!\n```\n"),
  "\n#### Note: this error code is no longer emitted by the compiler.\n\nThere are various restrictions on transmuting between types in Rust; for example\ntypes being transmuted must have the same size. To apply all these restrictions,\nthe compiler must know the exact types that may be transmuted. When type\nparameters are involved, this cannot always be done.\n\nSo, for example, the following is not allowed:\n\n```\nuse std::mem::transmute;\n\nstruct Foo<T>(Vec<T>);\n\nfn foo<T>(x: Vec<T>) {\n    // we are transmuting between Vec<T> and Foo<F> here\n    let y: Foo<T> = unsafe { transmute(x) };\n    // do something with y\n}\n```\n\nIn this specific case there\'s a good chance that the transmute is harmless (but\nthis is not guaranteed by Rust). However, when alignment and enum optimizations\ncome into the picture, it\'s quite likely that the sizes may or may not match\nwith different type parameter substitutions. It\'s not possible to check this for\n_all_ possible types, so `transmute()` simply only accepts types without any\nunsubstituted type parameters.\n\nIf you need this, there\'s a good chance you\'re doing something wrong. Keep in\nmind that Rust doesn\'t guarantee much about the layout of different structs\n(even two structs with identical declarations may have different layouts). If\nthere is a solution that avoids the transmute entirely, try it instead.\n\nIf it\'s possible, hand-monomorphize the code by writing the function for each\npossible type substitution. It\'s possible to use traits to do this cleanly,\nfor example:\n\n```\nuse std::mem::transmute;\n\nstruct Foo<T>(Vec<T>);\n\ntrait MyTransmutableType: Sized {\n    fn transmute(_: Vec<Self>) -> Foo<Self>;\n}\n\nimpl MyTransmutableType for u8 {\n    fn transmute(x: Vec<u8>) -> Foo<u8> {\n        unsafe { transmute(x) }\n    }\n}\n\nimpl MyTransmutableType for String {\n    fn transmute(x: Vec<String>) -> Foo<String> {\n        unsafe { transmute(x) }\n    }\n}\n\n// ... more impls for the types you intend to transmute\n\nfn foo<T: MyTransmutableType>(x: Vec<T>) {\n    let y: Foo<T> = <T as MyTransmutableType>::transmute(x);\n    // do something with y\n}\n```\n\nEach impl will be checked for a size match in the transmute as usual, and since\nthere are no unbound type parameters involved, this should compile unless there\nis a size mismatch in one of the impls.\n\nIt is also possible to manually transmute:\n\n```\n# use std::ptr;\n# let v = Some(\"value\");\n# type SomeType = &\'static [u8];\nunsafe {\n    ptr::read(&v as *const _ as *const SomeType) // `v` transmuted to `SomeType`\n}\n# ;\n```\n\nNote that this does not move `v` (unlike `transmute`), and may need a\ncall to `mem::forget(v)` in case you want to avoid destructors being called.\n"),
  "\nA lang item was redefined.\n\nErroneous code example:\n\n```compile_fail,E0152\n#![feature(lang_items)]\n\n#[lang = \"panic_fmt\"]\nstruct Foo; // error: duplicate lang item found: `panic_fmt`\n```\n\nLang items are already implemented in the standard library. Unless you are\nwriting a free-standing application (e.g. a kernel), you do not need to provide\nthem yourself.\n\nYou can build a free-standing crate by adding `#![no_std]` to the crate\nattributes:\n\n```ignore (only-for-syntax-highlight)\n#![no_std]\n```\n\nSee also\n"),
  "\nA generic type was described using parentheses rather than angle brackets.\nFor example:\n\n```compile_fail,E0214\nfn main() {\n    let v: Vec(&str) = vec![\"foo\"];\n}\n```\n\nThis is not currently supported: `v` should be defined as `Vec<&str>`.\nParentheses are currently only used with generic types when defining parameters\nfor `Fn`-family traits.\n"),
  "\nThe `#[rustc_on_unimplemented]` attribute lets you specify a custom error\nmessage for when a particular trait isn\'t implemented on a type placed in a\nposition that needs that trait. For example, when the following code is\ncompiled:\n\n```compile_fail\n#![feature(on_unimplemented)]\n\nfn foo<T: Index<u8>>(x: T){}\n\n#[rustc_on_unimplemented = \"the type `{Self}` cannot be indexed by `{Idx}`\"]\ntrait Index<Idx> { /* ... */ }\n\nfoo(true); // `bool` does not implement `Index<u8>`\n```\n\nThere will be an error about `bool` not implementing `Index<u8>`, followed by a\nnote saying \"the type `bool` cannot be indexed by `u8`\".\n\nAs you can see, you can specify type parameters in curly braces for\nsubstitution with the actual types (using the regular format string syntax) in\na given situation. Furthermore, `{Self}` will substitute to the type (in this\ncase, `bool`) that we tried to use.\n\nThis error appears when the curly braces contain an identifier which doesn\'t\nmatch with any of the type parameters or the string `Self`. This might happen\nif you misspelled a type parameter, or if you intended to use literal curly\nbraces. If it is the latter, escape the curly braces with a second curly brace\nof the same type; e.g. a literal `{` is `{{`.\n"),
  "\nThe `#[rustc_on_unimplemented]` attribute lets you specify a custom error\nmessage for when a particular trait isn\'t implemented on a type placed in a\nposition that needs that trait. For example, when the following code is\ncompiled:\n\n```compile_fail\n#![feature(on_unimplemented)]\n\nfn foo<T: Index<u8>>(x: T){}\n\n#[rustc_on_unimplemented = \"the type `{Self}` cannot be indexed by `{Idx}`\"]\ntrait Index<Idx> { /* ... */ }\n\nfoo(true); // `bool` does not implement `Index<u8>`\n```\n\nthere will be an error about `bool` not implementing `Index<u8>`, followed by a\nnote saying \"the type `bool` cannot be indexed by `u8`\".\n\nAs you can see, you can specify type parameters in curly braces for\nsubstitution with the actual types (using the regular format string syntax) in\na given situation. Furthermore, `{Self}` will substitute to the type (in this\ncase, `bool`) that we tried to use.\n\nThis error appears when the curly braces do not contain an identifier. Please\nadd one of the same name as a type parameter. If you intended to use literal\nbraces, use `{{` and `}}` to escape them.\n"),
  "\nThe `#[rustc_on_unimplemented]` attribute lets you specify a custom error\nmessage for when a particular trait isn\'t implemented on a type placed in a\nposition that needs that trait. For example, when the following code is\ncompiled:\n\n```compile_fail\n#![feature(on_unimplemented)]\n\nfn foo<T: Index<u8>>(x: T){}\n\n#[rustc_on_unimplemented = \"the type `{Self}` cannot be indexed by `{Idx}`\"]\ntrait Index<Idx> { /* ... */ }\n\nfoo(true); // `bool` does not implement `Index<u8>`\n```\n\nthere will be an error about `bool` not implementing `Index<u8>`, followed by a\nnote saying \"the type `bool` cannot be indexed by `u8`\".\n\nFor this to work, some note must be specified. An empty attribute will not do\nanything, please remove the attribute or add some helpful note for users of the\ntrait.\n"),
  "\nWhen using a lifetime like `\'a` in a type, it must be declared before being\nused.\n\nThese two examples illustrate the problem:\n\n```compile_fail,E0261\n// error, use of undeclared lifetime name `\'a`\nfn foo(x: &\'a str) { }\n\nstruct Foo {\n    // error, use of undeclared lifetime name `\'a`\n    x: &\'a str,\n}\n```\n\nThese can be fixed by declaring lifetime parameters:\n\n```\nfn foo<\'a>(x: &\'a str) {}\n\nstruct Foo<\'a> {\n    x: &\'a str,\n}\n```\n"),
  "\nDeclaring certain lifetime names in parameters is disallowed. For example,\nbecause the `\'static` lifetime is a special built-in lifetime name denoting\nthe lifetime of the entire program, this is an error:\n\n```compile_fail,E0262\n// error, invalid lifetime parameter name `\'static`\nfn foo<\'static>(x: &\'static str) { }\n```\n"),
  "\nA lifetime name cannot be declared more than once in the same scope. For\nexample:\n\n```compile_fail,E0263\n// error, lifetime name `\'a` declared twice in the same scope\nfn foo<\'a, \'b, \'a>(x: &\'a str, y: &\'b str) { }\n```\n"),
  "\nAn unknown external lang item was used. Erroneous code example:\n\n```compile_fail,E0264\n#![feature(lang_items)]\n\nextern \"C\" {\n    #[lang = \"cake\"] // error: unknown external lang item: `cake`\n    fn cake();\n}\n```\n\nA list of available external lang items is available in\n`src/librustc/middle/`. Example:\n\n```\n#![feature(lang_items)]\n\nextern \"C\" {\n    #[lang = \"panic_fmt\"] // ok!\n    fn cake();\n}\n```\n"),
  "\nThis is because of a type mismatch between the associated type of some\ntrait (e.g. `T::Bar`, where `T` implements `trait Quux { type Bar; }`)\nand another type `U` that is required to be equal to `T::Bar`, but is not.\nExamples follow.\n\nHere is a basic example:\n\n```compile_fail,E0271\ntrait Trait { type AssociatedType; }\n\nfn foo<T>(t: T) where T: Trait<AssociatedType=u32> {\n    println!(\"in foo\");\n}\n\nimpl Trait for i8 { type AssociatedType = &\'static str; }\n\nfoo(3_i8);\n```\n\nHere is that same example again, with some explanatory comments:\n\n```compile_fail,E0271\ntrait Trait { type AssociatedType; }\n\nfn foo<T>(t: T) where T: Trait<AssociatedType=u32> {\n//                    ~~~~~~~~ ~~~~~~~~~~~~~~~~~~\n//                        |            |\n//         This says `foo` can         |\n//           only be used with         |\n//              some type that         |\n//         implements `Trait`.         |\n//                                     |\n//                             This says not only must\n//                             `T` be an impl of `Trait`\n//                             but also that the impl\n//                             must assign the type `u32`\n//                             to the associated type.\n    println!(\"in foo\");\n}\n\nimpl Trait for i8 { type AssociatedType = &\'static str; }\n//~~~~~~~~~~~~~~~   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n//      |                             |\n// `i8` does have                     |\n// implementation                     |\n// of `Trait`...                      |\n//                     ... but it is an implementation\n//                     that assigns `&\'static str` to\n//                     the associated type.\n\nfoo(3_i8);\n// Here, we invoke `foo` with an `i8`, which does not satisfy\n// the constraint `<i8 as Trait>::AssociatedType=u32`, and\n// therefore the type-checker complains with this error code.\n```\n\nHere is a more subtle instance of the same problem, that can\narise with for-loops in Rust:\n\n```compile_fail\nlet vs: Vec<i32> = vec![1, 2, 3, 4];\nfor v in &vs {\n    match v {\n        1 => {},\n        _ => {},\n    }\n}\n```\n\nThe above fails because of an analogous type mismatch,\nthough may be harder to see. Again, here are some\nexplanatory comments for the same example:\n\n```compile_fail\n{\n    let vs = vec![1, 2, 3, 4];\n\n    // `for`-loops use a protocol based on the `Iterator`\n    // trait. Each item yielded in a `for` loop has the\n    // type `Iterator::Item` -- that is, `Item` is the\n    // associated type of the concrete iterator impl.\n    for v in &vs {\n//      ~    ~~~\n//      |     |\n//      |    We borrow `vs`, iterating over a sequence of\n//      |    *references* of type `&Elem` (where `Elem` is\n//      |    vector\'s element type). Thus, the associated\n//      |    type `Item` must be a reference `&`-type ...\n//      |\n//  ... and `v` has the type `Iterator::Item`, as dictated by\n//  the `for`-loop protocol ...\n\n        match v {\n            1 => {}\n//          ~\n//          |\n// ... but *here*, `v` is forced to have some integral type;\n// only types like `u8`,`i8`,`u16`,`i16`, et cetera can\n// match the pattern `1` ...\n\n            _ => {}\n        }\n\n// ... therefore, the compiler complains, because it sees\n// an attempt to solve the equations\n// `some integral-type` = type-of-`v`\n//                      = `Iterator::Item`\n//                      = `&Elem` (i.e. `some reference type`)\n//\n// which cannot possibly all be true.\n\n    }\n}\n```\n\nTo avoid those issues, you have to make the types match correctly.\nSo we can fix the previous examples like this:\n\n```\n// Basic Example:\ntrait Trait { type AssociatedType; }\n\nfn foo<T>(t: T) where T: Trait<AssociatedType = &\'static str> {\n    println!(\"in foo\");\n}\n\nimpl Trait for i8 { type AssociatedType = &\'static str; }\n\nfoo(3_i8);\n\n// For-Loop Example:\nlet vs = vec![1, 2, 3, 4];\nfor v in &vs {\n    match v {\n        &1 => {}\n        _ => {}\n    }\n}\n```\n"),
  "\nThis error occurs when there was a recursive trait requirement that overflowed\nbefore it could be evaluated. Often this means that there is unbounded\nrecursion in resolving some type bounds.\n\nFor example, in the following code:\n\n```compile_fail,E0275\ntrait Foo {}\n\nstruct Bar<T>(T);\n\nimpl<T> Foo for T where Bar<T>: Foo {}\n```\n\nTo determine if a `T` is `Foo`, we need to check if `Bar<T>` is `Foo`. However,\nto do this check, we need to determine that `Bar<Bar<T>>` is `Foo`. To\ndetermine this, we check if `Bar<Bar<Bar<T>>>` is `Foo`, and so on. This is\nclearly a recursive requirement that can\'t be resolved directly.\n\nConsider changing your trait bounds so that they\'re less self-referential.\n"),
  "\nThis error occurs when a bound in an implementation of a trait does not match\nthe bounds specified in the original trait. For example:\n\n```compile_fail,E0276\ntrait Foo {\n    fn foo<T>(x: T);\n}\n\nimpl Foo for bool {\n    fn foo<T>(x: T) where T: Copy {}\n}\n```\n\nHere, all types implementing `Foo` must have a method `foo<T>(x: T)` which can\ntake any type `T`. However, in the `impl` for `bool`, we have added an extra\nbound that `T` is `Copy`, which isn\'t compatible with the original trait.\n\nConsider removing the bound from the method or adding the bound to the original\nmethod definition in the trait.\n"),
  "\nYou tried to use a type which doesn\'t implement some trait in a place which\nexpected that trait. Erroneous code example:\n\n```compile_fail,E0277\n// here we declare the Foo trait with a bar method\ntrait Foo {\n    fn bar(&self);\n}\n\n// we now declare a function which takes an object implementing the Foo trait\nfn some_func<T: Foo>(foo: T) {\n;\n}\n\nfn main() {\n    // we now call the method with the i32 type, which doesn\'t implement\n    // the Foo trait\n    some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied\n}\n```\n\nIn order to fix this error, verify that the type you\'re using does implement\nthe trait. Example:\n\n```\ntrait Foo {\n    fn bar(&self);\n}\n\nfn some_func<T: Foo>(foo: T) {\n; // we can now use this method since i32 implements the\n               // Foo trait\n}\n\n// we implement the trait on the i32 type\nimpl Foo for i32 {\n    fn bar(&self) {}\n}\n\nfn main() {\n    some_func(5i32); // ok!\n}\n```\n\nOr in a generic context, an erroneous code example would look like:\n\n```compile_fail,E0277\nfn some_func<T>(foo: T) {\n    println!(\"{:?}\", foo); // error: the trait `core::fmt::Debug` is not\n                           //        implemented for the type `T`\n}\n\nfn main() {\n    // We now call the method with the i32 type,\n    // which *does* implement the Debug trait.\n    some_func(5i32);\n}\n```\n\nNote that the error here is in the definition of the generic function: Although\nwe only call it with a parameter that does implement `Debug`, the compiler\nstill rejects the function: It must work with all possible input types. In\norder to make this example compile, we need to restrict the generic type we\'re\naccepting:\n\n```\nuse std::fmt;\n\n// Restrict the input type to types that implement Debug.\nfn some_func<T: fmt::Debug>(foo: T) {\n    println!(\"{:?}\", foo);\n}\n\nfn main() {\n    // Calling the method is still fine, as i32 implements Debug.\n    some_func(5i32);\n\n    // This would fail to compile now:\n    // struct WithoutDebug;\n    // some_func(WithoutDebug);\n}\n```\n\nRust only looks at the signature of the called function, as such it must\nalready specify all requirements that will be used for every type parameter.\n"),
  "\n#### Note: this error code is no longer emitted by the compiler.\n\nYou tried to supply a type which doesn\'t implement some trait in a location\nwhich expected that trait. This error typically occurs when working with\n`Fn`-based types. Erroneous code example:\n\n```compile-fail\nfn foo<F: Fn(usize)>(x: F) { }\n\nfn main() {\n    // type mismatch: ... implements the trait `core::ops::Fn<(String,)>`,\n    // but the trait `core::ops::Fn<(usize,)>` is required\n    // [E0281]\n    foo(|y: String| { });\n}\n```\n\nThe issue in this case is that `foo` is defined as accepting a `Fn` with one\nargument of type `String`, but the closure we attempted to pass to it requires\none arguments of type `usize`.\n"),
  "\nThis error indicates that type inference did not result in one unique possible\ntype, and extra information is required. In most cases this can be provided\nby adding a type annotation. Sometimes you need to specify a generic type\nparameter manually.\n\nA common example is the `collect` method on `Iterator`. It has a generic type\nparameter with a `FromIterator` bound, which for a `char` iterator is\nimplemented by `Vec` and `String` among others. Consider the following snippet\nthat reverses the characters of a string:\n\n```compile_fail,E0282\nlet x = \"hello\".chars().rev().collect();\n```\n\nIn this case, the compiler cannot infer what the type of `x` should be:\n`Vec<char>` and `String` are both suitable candidates. To specify which type to\nuse, you can use a type annotation on `x`:\n\n```\nlet x: Vec<char> = \"hello\".chars().rev().collect();\n```\n\nIt is not necessary to annotate the full type. Once the ambiguity is resolved,\nthe compiler can infer the rest:\n\n```\nlet x: Vec<_> = \"hello\".chars().rev().collect();\n```\n\nAnother way to provide the compiler with enough information, is to specify the\ngeneric type parameter:\n\n```\nlet x = \"hello\".chars().rev().collect::<Vec<char>>();\n```\n\nAgain, you need not specify the full type if the compiler can infer it:\n\n```\nlet x = \"hello\".chars().rev().collect::<Vec<_>>();\n```\n\nApart from a method or function with a generic type parameter, this error can\noccur when a type parameter of a struct or trait cannot be inferred. In that\ncase it is not always possible to use a type annotation, because all candidates\nhave the same return type. For instance:\n\n```compile_fail,E0282\nstruct Foo<T> {\n    num: T,\n}\n\nimpl<T> Foo<T> {\n    fn bar() -> i32 {\n        0\n    }\n\n    fn baz() {\n        let number = Foo::bar();\n    }\n}\n```\n\nThis will fail because the compiler does not know which instance of `Foo` to\ncall `bar` on. Change `Foo::bar()` to `Foo::<T>::bar()` to resolve the error.\n"),
  "\nThis error occurs when the compiler doesn\'t have enough information\nto unambiguously choose an implementation.\n\nFor example:\n\n```compile_fail,E0283\ntrait Generator {\n    fn create() -> u32;\n}\n\nstruct Impl;\n\nimpl Generator for Impl {\n    fn create() -> u32 { 1 }\n}\n\nstruct AnotherImpl;\n\nimpl Generator for AnotherImpl {\n    fn create() -> u32 { 2 }\n}\n\nfn main() {\n    let cont: u32 = Generator::create();\n    // error, impossible to choose one of Generator trait implementation\n    // Impl or AnotherImpl? Maybe anything else?\n}\n```\n\nTo resolve this error use the concrete type:\n\n```\ntrait Generator {\n    fn create() -> u32;\n}\n\nstruct AnotherImpl;\n\nimpl Generator for AnotherImpl {\n    fn create() -> u32 { 2 }\n}\n\nfn main() {\n    let gen1 = AnotherImpl::create();\n\n    // if there are multiple methods with same name (different traits)\n    let gen2 = <AnotherImpl as Generator>::create();\n}\n```\n"),
  "\nThis error indicates that the given recursion limit could not be parsed. Ensure\nthat the value provided is a positive integer between quotes.\n\nErroneous code example:\n\n```compile_fail,E0296\n#![recursion_limit]\n\nfn main() {}\n```\n\nAnd a working example:\n\n```\n#![recursion_limit=\"1000\"]\n\nfn main() {}\n```\n"),
  "\nThis error occurs when the compiler was unable to infer the concrete type of a\nvariable. It can occur for several cases, the most common of which is a\nmismatch in the expected type that the compiler inferred for a variable\'s\ninitializing expression, and the actual type explicitly assigned to the\nvariable.\n\nFor example:\n\n```compile_fail,E0308\nlet x: i32 = \"I am not a number!\";\n//     ~~~   ~~~~~~~~~~~~~~~~~~~~\n//      |             |\n//      |    initializing expression;\n//      |    compiler infers type `&str`\n//      |\n//    type `i32` assigned to variable `x`\n```\n"),
  "\nTypes in type definitions have lifetimes associated with them that represent\nhow long the data stored within them is guaranteed to be live. This lifetime\nmust be as long as the data needs to be alive, and missing the constraint that\ndenotes this will cause this error.\n\n```compile_fail,E0309\n// This won\'t compile because T is not constrained, meaning the data\n// stored in it is not guaranteed to last as long as the reference\nstruct Foo<\'a, T> {\n    foo: &\'a T\n}\n```\n\nThis will compile, because it has the constraint on the type parameter:\n\n```\nstruct Foo<\'a, T: \'a> {\n    foo: &\'a T\n}\n```\n\nTo see why this is important, consider the case where `T` is itself a reference\n(e.g., `T = &str`). If we don\'t include the restriction that `T: \'a`, the\nfollowing code would be perfectly legal:\n\n```compile_fail,E0309\nstruct Foo<\'a, T> {\n    foo: &\'a T\n}\n\nfn main() {\n    let v = \"42\".to_string();\n    let f = Foo{foo: &v};\n    drop(v);\n    println!(\"{}\",; // but we\'ve already dropped v!\n}\n```\n"),
  "\nTypes in type definitions have lifetimes associated with them that represent\nhow long the data stored within them is guaranteed to be live. This lifetime\nmust be as long as the data needs to be alive, and missing the constraint that\ndenotes this will cause this error.\n\n```compile_fail,E0310\n// This won\'t compile because T is not constrained to the static lifetime\n// the reference needs\nstruct Foo<T> {\n    foo: &\'static T\n}\n```\n\nThis will compile, because it has the constraint on the type parameter:\n\n```\nstruct Foo<T: \'static> {\n    foo: &\'static T\n}\n```\n"),
  "\nThis error occurs when an `if` expression without an `else` block is used in a\ncontext where a type other than `()` is expected, for example a `let`\nexpression:\n\n```compile_fail,E0317\nfn main() {\n    let x = 5;\n    let a = if x == 5 { 1 };\n}\n```\n\nAn `if` expression without an `else` block has the type `()`, so this is a type\nerror. To resolve it, add an `else` block having the same type as the `if`\nblock.\n"),
  "\nThis error indicates that some types or traits depend on each other\nand therefore cannot be constructed.\n\nThe following example contains a circular dependency between two traits:\n\n```compile_fail,E0391\ntrait FirstTrait : SecondTrait {\n\n}\n\ntrait SecondTrait : FirstTrait {\n\n}\n```\n"),
  "\n#### Note: this error code is no longer emitted by the compiler.\n\nIn Rust 1.3, the default object lifetime bounds are expected to change, as\ndescribed in [RFC 1156]. You are getting a warning because the compiler\nthinks it is possible that this change will cause a compilation error in your\ncode. It is possible, though unlikely, that this is a false alarm.\n\nThe heart of the change is that where `&\'a Box<SomeTrait>` used to default to\n`&\'a Box<SomeTrait+\'a>`, it now defaults to `&\'a Box<SomeTrait+\'static>` (here,\n`SomeTrait` is the name of some trait type). Note that the only types which are\naffected are references to boxes, like `&Box<SomeTrait>` or\n`&[Box<SomeTrait>]`. More common types like `&SomeTrait` or `Box<SomeTrait>`\nare unaffected.\n\nTo silence this warning, edit your code to use an explicit bound. Most of the\ntime, this means that you will want to change the signature of a function that\nyou are calling. For example, if the error is reported on a call like `foo(x)`,\nand `foo` is defined as follows:\n\n```\n# trait SomeTrait {}\nfn foo(arg: &Box<SomeTrait>) { /* ... */ }\n```\n\nYou might change it to:\n\n```\n# trait SomeTrait {}\nfn foo<\'a>(arg: &\'a Box<SomeTrait+\'a>) { /* ... */ }\n```\n\nThis explicitly states that you expect the trait object `SomeTrait` to contain\nreferences (with a maximum lifetime of `\'a`).\n\n[RFC 1156]:\n"),
  "\nAn invalid lint attribute has been given. Erroneous code example:\n\n```compile_fail,E0452\n#![allow(foo = \"\")] // error: malformed lint attribute\n```\n\nLint attributes only accept a list of identifiers (where each identifier is a\nlint name). Ensure the attribute is of this form:\n\n```\n#![allow(foo)] // ok!\n// or:\n#![allow(foo, foo2)] // ok!\n```\n"),
  "\nA lint check attribute was overruled by a `forbid` directive set as an\nattribute on an enclosing scope, or on the command line with the `-F` option.\n\nExample of erroneous code:\n\n```compile_fail,E0453\n#![forbid(non_snake_case)]\n\n#[allow(non_snake_case)]\nfn main() {\n    let MyNumber = 2; // error: allow(non_snake_case) overruled by outer\n                      //        forbid(non_snake_case)\n}\n```\n\nThe `forbid` lint setting, like `deny`, turns the corresponding compiler\nwarning into a hard error. Unlike `deny`, `forbid` prevents itself from being\noverridden by inner attributes.\n\nIf you\'re sure you want to override the lint check, you can change `forbid` to\n`deny` (or use `-D` instead of `-F` if the `forbid` setting was given as a\ncommand-line option) to allow the inner lint check attribute:\n\n```\n#![deny(non_snake_case)]\n\n#[allow(non_snake_case)]\nfn main() {\n    let MyNumber = 2; // ok!\n}\n```\n\nOtherwise, edit the code to pass the lint check, and remove the overruled\nattribute:\n\n```\n#![forbid(non_snake_case)]\n\nfn main() {\n    let my_number = 2;\n}\n```\n"),
  "\nA lifetime bound was not satisfied.\n\nErroneous code example:\n\n```compile_fail,E0478\n// Check that the explicit lifetime bound (`\'SnowWhite`, in this example) must\n// outlive all the superbounds from the trait (`\'kiss`, in this example).\n\ntrait Wedding<\'t>: \'t { }\n\nstruct Prince<\'kiss, \'SnowWhite> {\n    child: Box<Wedding<\'kiss> + \'SnowWhite>,\n    // error: lifetime bound not satisfied\n}\n```\n\nIn this example, the `\'SnowWhite` lifetime is supposed to outlive the `\'kiss`\nlifetime but the declaration of the `Prince` struct doesn\'t enforce it. To fix\nthis issue, you need to specify it:\n\n```\ntrait Wedding<\'t>: \'t { }\n\nstruct Prince<\'kiss, \'SnowWhite: \'kiss> { // You say here that \'kiss must live\n                                          // longer than \'SnowWhite.\n    child: Box<Wedding<\'kiss> + \'SnowWhite>, // And now it\'s all good!\n}\n```\n"),
  "\nA reference has a longer lifetime than the data it references.\n\nErroneous code example:\n\n```compile_fail,E0491\n// struct containing a reference requires a lifetime parameter,\n// because the data the reference points to must outlive the struct (see E0106)\nstruct Struct<\'a> {\n    ref_i32: &\'a i32,\n}\n\n// However, a nested struct like this, the signature itself does not tell\n// whether \'a outlives \'b or the other way around.\n// So it could be possible that \'b of reference outlives \'a of the data.\nstruct Nested<\'a, \'b> {\n    ref_struct: &\'b Struct<\'a>, // compile error E0491\n}\n```\n\nTo fix this issue, you can specify a bound to the lifetime like below:\n\n```\nstruct Struct<\'a> {\n    ref_i32: &\'a i32,\n}\n\n// \'a: \'b means \'a outlives \'b\nstruct Nested<\'a: \'b, \'b> {\n    ref_struct: &\'b Struct<\'a>,\n}\n```\n"),
  "\nA lifetime name is shadowing another lifetime name. Erroneous code example:\n\n```compile_fail,E0496\nstruct Foo<\'a> {\n    a: &\'a i32,\n}\n\nimpl<\'a> Foo<\'a> {\n    fn f<\'a>(x: &\'a i32) { // error: lifetime name `\'a` shadows a lifetime\n                           //        name that is already in scope\n    }\n}\n```\n\nPlease change the name of one of the lifetimes to remove this error. Example:\n\n```\nstruct Foo<\'a> {\n    a: &\'a i32,\n}\n\nimpl<\'a> Foo<\'a> {\n    fn f<\'b>(x: &\'b i32) { // ok!\n    }\n}\n\nfn main() {\n}\n```\n"),
  "\nA stability attribute was used outside of the standard library. Erroneous code\nexample:\n\n```compile_fail\n#[stable] // error: stability attributes may not be used outside of the\n          //        standard library\nfn foo() {}\n```\n\nIt is not possible to use stability attributes outside of the standard library.\nAlso, for now, it is not possible to write deprecation messages either.\n"),
  "\nTransmute with two differently sized types was attempted. Erroneous code\nexample:\n\n```compile_fail,E0512\nfn takes_u8(_: u8) {}\n\nfn main() {\n    unsafe { takes_u8(::std::mem::transmute(0u16)); }\n    // error: transmute called with types of different sizes\n}\n```\n\nPlease use types with same size or use the expected type directly. Example:\n\n```\nfn takes_u8(_: u8) {}\n\nfn main() {\n    unsafe { takes_u8(::std::mem::transmute(0i8)); } // ok!\n    // or:\n    unsafe { takes_u8(0u8); } // ok!\n}\n```\n"),
  "\nThis error indicates that a `#[repr(..)]` attribute was placed on an\nunsupported item.\n\nExamples of erroneous code:\n\n```compile_fail,E0517\n#[repr(C)]\ntype Foo = u8;\n\n#[repr(packed)]\nenum Foo {Bar, Baz}\n\n#[repr(u8)]\nstruct Foo {bar: bool, baz: bool}\n\n#[repr(C)]\nimpl Foo {\n    // ...\n}\n```\n\n* The `#[repr(C)]` attribute can only be placed on structs and enums.\n* The `#[repr(packed)]` and `#[repr(simd)]` attributes only work on structs.\n* The `#[repr(u8)]`, `#[repr(i16)]`, etc attributes only work on enums.\n\nThese attributes do not work on typedefs, since typedefs are just aliases.\n\nRepresentations like `#[repr(u8)]`, `#[repr(i64)]` are for selecting the\ndiscriminant size for C-like enums (when there is no associated data, e.g.\n`enum Color {Red, Blue, Green}`), effectively setting the size of the enum to\nthe size of the provided type. Such an enum can be cast to a value of the same\ntype as well. In short, `#[repr(u8)]` makes the enum behave like an integer\nwith a constrained set of allowed values.\n\nOnly C-like enums can be cast to numerical primitives, so this attribute will\nnot apply to structs.\n\n`#[repr(packed)]` reduces padding to make the struct size smaller. The\nrepresentation of enums isn\'t strictly defined in Rust, and this attribute\nwon\'t work on enums.\n\n`#[repr(simd)]` will give a struct consisting of a homogeneous series of machine\ntypes (i.e. `u8`, `i32`, etc) a representation that permits vectorization via\nSIMD. This doesn\'t make much sense for enums since they don\'t consist of a\nsingle list of data.\n"),
  "\nThis error indicates that an `#[inline(..)]` attribute was incorrectly placed\non something other than a function or method.\n\nExamples of erroneous code:\n\n```compile_fail,E0518\n#[inline(always)]\nstruct Foo;\n\n#[inline(never)]\nimpl Foo {\n    // ...\n}\n```\n\n`#[inline]` hints the compiler whether or not to attempt to inline a method or\nfunction. By default, the compiler does a pretty good job of figuring this out\nitself, but if you feel the need for annotations, `#[inline(always)]` and\n`#[inline(never)]` can override or force the compiler\'s decision.\n\nIf you wish to apply this attribute to all methods in an impl, manually annotate\neach method; it is not possible to annotate the entire impl with an `#[inline]`\nattribute.\n"),
  "\nThe lang attribute is intended for marking special items that are built-in to\nRust itself. This includes special traits (like `Copy` and `Sized`) that affect\nhow the compiler behaves, as well as special functions that may be automatically\ninvoked (such as the handler for out-of-bounds accesses when indexing a slice).\nErroneous code example:\n\n```compile_fail,E0522\n#![feature(lang_items)]\n\n#[lang = \"cookie\"]\nfn cookie() -> ! { // error: definition of an unknown language item: `cookie`\n    loop {}\n}\n```\n"),
  "\nA closure was used but didn\'t implement the expected trait.\n\nErroneous code example:\n\n```compile_fail,E0525\nstruct X;\n\nfn foo<T>(_: T) {}\nfn bar<T: Fn(u32)>(_: T) {}\n\nfn main() {\n    let x = X;\n    let closure = |_| foo(x); // error: expected a closure that implements\n                              //        the `Fn` trait, but this closure only\n                              //        implements `FnOnce`\n    bar(closure);\n}\n```\n\nIn the example above, `closure` is an `FnOnce` closure whereas the `bar`\nfunction expected an `Fn` closure. In this case, it\'s simple to fix the issue,\nyou just have to implement `Copy` and `Clone` traits on `struct X` and it\'ll\nbe ok:\n\n```\n#[derive(Clone, Copy)] // We implement `Clone` and `Copy` traits.\nstruct X;\n\nfn foo<T>(_: T) {}\nfn bar<T: Fn(u32)>(_: T) {}\n\nfn main() {\n    let x = X;\n    let closure = |_| foo(x);\n    bar(closure); // ok!\n}\n```\n\nTo understand better how closures work in Rust, read:\n\n"),
  "\nThe `main` function was incorrectly declared.\n\nErroneous code example:\n\n```compile_fail,E0580\nfn main() -> i32 { // error: main function has wrong type\n    0\n}\n```\n\nThe `main` function prototype should never take arguments or return type.\nExample:\n\n```\nfn main() {\n    // your code\n}\n```\n\nIf you want to get command-line arguments, use `std::env::args`. To exit with a\nspecified exit code, use `std::process::exit`.\n"),
  "\nPer [RFC 401][rfc401], if you have a function declaration `foo`:\n\n```\n// For the purposes of this explanation, all of these\n// different kinds of `fn` declarations are equivalent:\nstruct S;\nfn foo(x: S) { /* ... */ }\n# #[cfg(for_demonstration_only)]\nextern \"C\" { fn foo(x: S); }\n# #[cfg(for_demonstration_only)]\nimpl S { fn foo(self) { /* ... */ } }\n```\n\nthe type of `foo` is **not** `fn(S)`, as one might expect.\nRather, it is a unique, zero-sized marker type written here as `typeof(foo)`.\nHowever, `typeof(foo)` can be _coerced_ to a function pointer `fn(S)`,\nso you rarely notice this:\n\n```\n# struct S;\n# fn foo(_: S) {}\nlet x: fn(S) = foo; // OK, coerces\n```\n\nThe reason that this matter is that the type `fn(S)` is not specific to\nany particular function: it\'s a function _pointer_. So calling `x()` results\nin a virtual call, whereas `foo()` is statically dispatched, because the type\nof `foo` tells us precisely what function is being called.\n\nAs noted above, coercions mean that most code doesn\'t have to be\nconcerned with this distinction. However, you can tell the difference\nwhen using **transmute** to convert a fn item into a fn pointer.\n\nThis is sometimes done as part of an FFI:\n\n```compile_fail,E0591\nextern \"C\" fn foo(userdata: Box<i32>) {\n    /* ... */\n}\n\n# fn callback(_: extern \"C\" fn(*mut i32)) {}\n# use std::mem::transmute;\n# unsafe {\nlet f: extern \"C\" fn(*mut i32) = transmute(foo);\ncallback(f);\n# }\n```\n\nHere, transmute is being used to convert the types of the fn arguments.\nThis pattern is incorrect because, because the type of `foo` is a function\n**item** (`typeof(foo)`), which is zero-sized, and the target type (`fn()`)\nis a function pointer, which is not zero-sized.\nThis pattern should be rewritten. There are a few possible ways to do this:\n\n- change the original fn declaration to match the expected signature,\n  and do the cast in the fn body (the prefered option)\n- cast the fn item fo a fn pointer before calling transmute, as shown here:\n\n    ```\n    # extern \"C\" fn foo(_: Box<i32>) {}\n    # use std::mem::transmute;\n    # unsafe {\n    let f: extern \"C\" fn(*mut i32) = transmute(foo as extern \"C\" fn(_));\n    let f: extern \"C\" fn(*mut i32) = transmute(foo as usize); // works too\n    # }\n    ```\n\nThe same applies to transmutes to `*mut fn()`, which were observedin practice.\nNote though that use of this type is generally incorrect.\nThe intention is typically to describe a function pointer, but just `fn()`\nalone suffices for that. `*mut fn()` is a pointer to a fn pointer.\n(Since these values are typically just passed to C code, however, this rarely\nmakes a difference in practice.)\n\n[rfc401]:\n"),
  "\nYou tried to supply an `Fn`-based type with an incorrect number of arguments\nthan what was expected.\n\nErroneous code example:\n\n```compile_fail,E0593\nfn foo<F: Fn()>(x: F) { }\n\nfn main() {\n    // [E0593] closure takes 1 argument but 0 arguments are required\n    foo(|y| { });\n}\n```\n"),
  "\nNo `main` function was found in a binary crate. To fix this error, add a\n`main` function. For example:\n\n```\nfn main() {\n    // Your program will start here.\n    println!(\"Hello world!\");\n}\n```\n\nIf you don\'t know the basics of Rust, you can go look to the Rust Book to get\nstarted:\n"),
  "\nAn unknown lint was used on the command line.\n\nErroneous example:\n\n```sh\nrustc -D bogus\n```\n\nMaybe you just misspelled the lint name or the lint doesn\'t exist anymore.\nEither way, try to update/remove it in order to fix the error.\n"),
  "\nThis error code indicates a mismatch between the lifetimes appearing in the\nfunction signature (i.e., the parameter types and the return type) and the\ndata-flow found in the function body.\n\nErroneous code example:\n\n```compile_fail,E0621\nfn foo<\'a>(x: &\'a i32, y: &i32) -> &\'a i32 { // error: explicit lifetime\n                                             //        required in the type of\n                                             //        `y`\n    if x > y { x } else { y }\n}\n```\n\nIn the code above, the function is returning data borrowed from either `x` or\n`y`, but the `\'a` annotation indicates that it is returning data only from `x`.\nTo fix the error, the signature and the body must be made to match. Typically,\nthis is done by updating the function signature. So, in this case, we change\nthe type of `y` to `&\'a i32`, like so:\n\n```\nfn foo<\'a>(x: &\'a i32, y: &\'a i32) -> &\'a i32 {\n    if x > y { x } else { y }\n}\n```\n\nNow the signature indicates that the function data borrowed from either `x` or\n`y`. Alternatively, you could change the body to not return data from `y`:\n\n```\nfn foo<\'a>(x: &\'a i32, y: &i32) -> &\'a i32 {\n    x\n}\n```\n")]
🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from via Cargo.toml instead?