rustc_const_eval::DIAGNOSTICS [] [src]

pub const DIAGNOSTICS: [(&'static str, &'static str); 18usize] = [("E0001",
  "\nThis error suggests that the expression arm corresponding to the noted pattern\nwill never be reached as for all possible values of the expression being\nmatched, one of the preceding patterns will match.\n\nThis means that perhaps some of the preceding patterns are too general, this\none is too specific or the ordering is incorrect.\n\nFor example, the following `match` block has too many arms:\n\n```compile_fail\nmatch foo {\n    Some(bar) => {/* ... */}\n    None => {/* ... */}\n    _ => {/* ... */} // All possible cases have already been handled\n}\n```\n\n`match` blocks have their patterns matched in order, so, for example, putting\na wildcard arm above a more specific arm will make the latter arm irrelevant.\n\nEnsure the ordering of the match arm is correct and remove any superfluous\narms.\n"),
 ("E0002",
  "\nThis error indicates that an empty match expression is invalid because the type\nit is matching on is non-empty (there exist values of this type). In safe code\nit is impossible to create an instance of an empty type, so empty match\nexpressions are almost never desired. This error is typically fixed by adding\none or more cases to the match expression.\n\nAn example of an empty type is `enum Empty { }`. So, the following will work:\n\n```\nenum Empty {}\n\nfn foo(x: Empty) {\n    match x {\n        // empty\n    }\n}\n```\n\nHowever, this won\'t:\n\n```compile_fail\nfn foo(x: Option<String>) {\n    match x {\n        // empty\n    }\n}\n```\n"),
 ("E0003",
  "\nNot-a-Number (NaN) values cannot be compared for equality and hence can never\nmatch the input to a match expression. So, the following will not compile:\n\n```compile_fail\nconst NAN: f32 = 0.0 / 0.0;\n\nlet number = 0.1f32;\n\nmatch number {\n    NAN => { /* ... */ },\n    _ => {}\n}\n```\n\nTo match against NaN values, you should instead use the `is_nan()` method in a\nguard, like so:\n\n```\nlet number = 0.1f32;\n\nmatch number {\n    x if x.is_nan() => { /* ... */ }\n    _ => {}\n}\n```\n"),
 ("E0004",
  "\nThis error indicates that the compiler cannot guarantee a matching pattern for\none or more possible inputs to a match expression. Guaranteed matches are\nrequired in order to assign values to match expressions, or alternatively,\ndetermine the flow of execution. Erroneous code example:\n\n```compile_fail\nenum Terminator {\n    HastaLaVistaBaby,\n    TalkToMyHand,\n}\n\nlet x = Terminator::HastaLaVistaBaby;\n\nmatch x { // error: non-exhaustive patterns: `HastaLaVistaBaby` not covered\n    Terminator::TalkToMyHand => {}\n}\n```\n\nIf you encounter this error you must alter your patterns so that every possible\nvalue of the input type is matched. For types with a small number of variants\n(like enums) you should probably cover all cases explicitly. Alternatively, the\nunderscore `_` wildcard pattern can be added after all other patterns to match\n\"anything else\". Example:\n\n```\nenum Terminator {\n    HastaLaVistaBaby,\n    TalkToMyHand,\n}\n\nlet x = Terminator::HastaLaVistaBaby;\n\nmatch x {\n    Terminator::TalkToMyHand => {}\n    Terminator::HastaLaVistaBaby => {}\n}\n\n// or:\n\nmatch x {\n    Terminator::TalkToMyHand => {}\n    _ => {}\n}\n```\n"),
 ("E0005",
  "\nPatterns used to bind names must be irrefutable, that is, they must guarantee\nthat a name will be extracted in all cases. Erroneous code example:\n\n```compile_fail\nlet x = Some(1);\nlet Some(y) = x;\n// error: refutable pattern in local binding: `None` not covered\n```\n\nIf you encounter this error you probably need to use a `match` or `if let` to\ndeal with the possibility of failure. Example:\n\n```compile_fail\nlet x = Some(1);\n\nmatch x {\n    Some(y) => {\n        // do something\n    },\n    None => {}\n}\n\n// or:\n\nif let Some(y) = x {\n    // do something\n}\n```\n"),
 ("E0007",
  "\nThis error indicates that the bindings in a match arm would require a value to\nbe moved into more than one location, thus violating unique ownership. Code\nlike the following is invalid as it requires the entire `Option<String>` to be\nmoved into a variable called `op_string` while simultaneously requiring the\ninner `String` to be moved into a variable called `s`.\n\n```compile_fail\nlet x = Some(\"s\".to_string());\n\nmatch x {\n    op_string @ Some(s) => {}, // error: cannot bind by-move with sub-bindings\n    None => {},\n}\n```\n\nSee also the error E0303.\n"),
 ("E0008",
  "\nNames bound in match arms retain their type in pattern guards. As such, if a\nname is bound by move in a pattern, it should also be moved to wherever it is\nreferenced in the pattern guard code. Doing so however would prevent the name\nfrom being available in the body of the match arm. Consider the following:\n\n```compile_fail\nmatch Some(\"hi\".to_string()) {\n    Some(s) if s.len() == 0 => {}, // use s.\n    _ => {},\n}\n```\n\nThe variable `s` has type `String`, and its use in the guard is as a variable of\ntype `String`. The guard code effectively executes in a separate scope to the\nbody of the arm, so the value would be moved into this anonymous scope and\ntherefore becomes unavailable in the body of the arm.\n\nThe problem above can be solved by using the `ref` keyword.\n\n```\nmatch Some(\"hi\".to_string()) {\n    Some(ref s) if s.len() == 0 => {},\n    _ => {},\n}\n```\n\nThough this example seems innocuous and easy to solve, the problem becomes clear\nwhen it encounters functions which consume the value:\n\n```compile_fail\nstruct A{}\n\nimpl A {\n    fn consume(self) -> usize {\n        0\n    }\n}\n\nfn main() {\n    let a = Some(A{});\n    match a {\n        Some(y) if y.consume() > 0 => {}\n        _ => {}\n    }\n}\n```\n\nIn this situation, even the `ref` keyword cannot solve it, since borrowed\ncontent cannot be moved. This problem cannot be solved generally. If the value\ncan be cloned, here is a not-so-specific solution:\n\n```\n#[derive(Clone)]\nstruct A{}\n\nimpl A {\n    fn consume(self) -> usize {\n        0\n    }\n}\n\nfn main() {\n    let a = Some(A{});\n    match a{\n        Some(ref y) if y.clone().consume() > 0 => {}\n        _ => {}\n    }\n}\n```\n\nIf the value will be consumed in the pattern guard, using its clone will not\nmove its ownership, so the code works.\n"),
 ("E0009",
  "\nIn a pattern, all values that don\'t implement the `Copy` trait have to be bound\nthe same way. The goal here is to avoid binding simultaneously by-move and\nby-ref.\n\nThis limitation may be removed in a future version of Rust.\n\nErroneous code example:\n\n```compile_fail\nstruct X { x: (), }\n\nlet x = Some((X { x: () }, X { x: () }));\nmatch x {\n    Some((y, ref z)) => {}, // error: cannot bind by-move and by-ref in the\n                            //        same pattern\n    None => panic!()\n}\n```\n\nYou have two solutions:\n\nSolution #1: Bind the pattern\'s values the same way.\n\n```\nstruct X { x: (), }\n\nlet x = Some((X { x: () }, X { x: () }));\nmatch x {\n    Some((ref y, ref z)) => {},\n    // or Some((y, z)) => {}\n    None => panic!()\n}\n```\n\nSolution #2: Implement the `Copy` trait for the `X` structure.\n\nHowever, please keep in mind that the first solution should be preferred.\n\n```\n#[derive(Clone, Copy)]\nstruct X { x: (), }\n\nlet x = Some((X { x: () }, X { x: () }));\nmatch x {\n    Some((y, ref z)) => {},\n    None => panic!()\n}\n```\n"),
 ("E0158",
  "\n`const` and `static` mean different things. A `const` is a compile-time\nconstant, an alias for a literal value. This property means you can match it\ndirectly within a pattern.\n\nThe `static` keyword, on the other hand, guarantees a fixed location in memory.\nThis does not always mean that the value is constant. For example, a global\nmutex can be declared `static` as well.\n\nIf you want to match against a `static`, consider using a guard instead:\n\n```\nstatic FORTY_TWO: i32 = 42;\n\nmatch Some(42) {\n    Some(x) if x == FORTY_TWO => {}\n    _ => {}\n}\n```\n"),
 ("E0162",
  "\nAn if-let pattern attempts to match the pattern, and enters the body if the\nmatch was successful. If the match is irrefutable (when it cannot fail to\nmatch), use a regular `let`-binding instead. For instance:\n\n```compile_fail\nstruct Irrefutable(i32);\nlet irr = Irrefutable(0);\n\n// This fails to compile because the match is irrefutable.\nif let Irrefutable(x) = irr {\n    // This body will always be executed.\n    foo(x);\n}\n```\n\nTry this instead:\n\n```ignore\nstruct Irrefutable(i32);\nlet irr = Irrefutable(0);\n\nlet Irrefutable(x) = irr;\nfoo(x);\n```\n"),
 ("E0165",
  "\nA while-let pattern attempts to match the pattern, and enters the body if the\nmatch was successful. If the match is irrefutable (when it cannot fail to\nmatch), use a regular `let`-binding inside a `loop` instead. For instance:\n\n```compile_fail\nstruct Irrefutable(i32);\nlet irr = Irrefutable(0);\n\n// This fails to compile because the match is irrefutable.\nwhile let Irrefutable(x) = irr {\n    ...\n}\n\nTry this instead:\n\n```\nstruct Irrefutable(i32);\nlet irr = Irrefutable(0);\n\nloop {\n    let Irrefutable(x) = irr;\n    ...\n}\n```\n"),
 ("E0170",
  "\nEnum variants are qualified by default. For example, given this type:\n\n```\nenum Method {\n    GET,\n    POST,\n}\n```\n\nYou would match it using:\n\n```\nenum Method {\n    GET,\n    POST,\n}\n\nlet m = Method::GET;\n\nmatch m {\n    Method::GET => {},\n    Method::POST => {},\n}\n```\n\nIf you don\'t qualify the names, the code will bind new variables named \"GET\" and\n\"POST\" instead. This behavior is likely not what you want, so `rustc` warns when\nthat happens.\n\nQualified names are good practice, and most code works well with them. But if\nyou prefer them unqualified, you can import the variants into scope:\n\n```ignore\nuse Method::*;\nenum Method { GET, POST }\n```\n\nIf you want others to be able to import variants from your module directly, use\n`pub use`:\n\n```ignore\npub use Method::*;\nenum Method { GET, POST }\n```\n"),
 ("E0297",
  "\nPatterns used to bind names must be irrefutable. That is, they must guarantee\nthat a name will be extracted in all cases. Instead of pattern matching the\nloop variable, consider using a `match` or `if let` inside the loop body. For\ninstance:\n\n```compile_fail\nlet xs : Vec<Option<i32>> = vec!(Some(1), None);\n\n// This fails because `None` is not covered.\nfor Some(x) in xs {\n    // ...\n}\n```\n\nMatch inside the loop instead:\n\n```\nlet xs : Vec<Option<i32>> = vec!(Some(1), None);\n\nfor item in xs {\n    match item {\n        Some(x) => {},\n        None => {},\n    }\n}\n```\n\nOr use `if let`:\n\n```\nlet xs : Vec<Option<i32>> = vec!(Some(1), None);\n\nfor item in xs {\n    if let Some(x) = item {\n        // ...\n    }\n}\n```\n"),
 ("E0301",
  "\nMutable borrows are not allowed in pattern guards, because matching cannot have\nside effects. Side effects could alter the matched object or the environment\non which the match depends in such a way, that the match would not be\nexhaustive. For instance, the following would not match any arm if mutable\nborrows were allowed:\n\n```compile_fail\nmatch Some(()) {\n    None => { },\n    option if option.take().is_none() => {\n        /* impossible, option is `Some` */\n    },\n    Some(_) => { } // When the previous match failed, the option became `None`.\n}\n```\n"),
 ("E0302",
  "\nAssignments are not allowed in pattern guards, because matching cannot have\nside effects. Side effects could alter the matched object or the environment\non which the match depends in such a way, that the match would not be\nexhaustive. For instance, the following would not match any arm if assignments\nwere allowed:\n\n```compile_fail\nmatch Some(()) {\n    None => { },\n    option if { option = None; false } { },\n    Some(_) => { } // When the previous match failed, the option became `None`.\n}\n```\n"),
 ("E0303",
  "\nIn certain cases it is possible for sub-bindings to violate memory safety.\nUpdates to the borrow checker in a future version of Rust may remove this\nrestriction, but for now patterns must be rewritten without sub-bindings.\n\n```ignore\n// Before.\nmatch Some(\"hi\".to_string()) {\n    ref op_string_ref @ Some(s) => {},\n    None => {},\n}\n\n// After.\nmatch Some(\"hi\".to_string()) {\n    Some(ref s) => {\n        let op_string_ref = &Some(s);\n        // ...\n    },\n    None => {},\n}\n```\n\nThe `op_string_ref` binding has type `&Option<&String>` in both cases.\n\nSee also https://github.com/rust-lang/rust/issues/14587\n"),
 ("E0306",
  "\nIn an array literal `[x; N]`, `N` is the number of elements in the array. This\nmust be an unsigned integer. Erroneous code example:\n\n```compile_fail\nlet x = [0i32; true]; // error: expected positive integer for repeat count,\n                      //        found boolean\n```\n\nWorking example:\n\n```\nlet x = [0i32; 2];\n```\n"),
 ("E0307",
  "\nThe length of an array is part of its type. For this reason, this length must\nbe a compile-time constant. Erroneous code example:\n\n```compile_fail\n    let len = 10;\n    let x = [0i32; len]; // error: expected constant integer for repeat count,\n                         //        found variable\n```\n\nWorking example:\n\n```\nlet x = [0i32; 10];\n```\n")]
Unstable (rustc_private)