From 3f428cc18a8b60daed9fdd39ddcf73ae7e3b1711 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 23 Apr 2015 11:30:42 +0200 Subject: [PATCH] Update diagnostics.rs --- src/librustc/diagnostics.rs | 100 ++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 43 deletions(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 4c88e6f464ec..73abac5abbb1 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -278,10 +278,12 @@ enum Method { you would match it using: +``` match m { Method::GET => ... Method::POST => ... } +``` If you don't qualify the names, the code will bind new variables named "GET" and "POST" instead. This behavior is likely not what you want, so rustc warns when @@ -290,8 +292,10 @@ that happens. Qualified names are good practice, and most code works well with them. But if you prefer them unqualified, you can import the variants into scope: - use Method::*; - enum Method { GET, POST } +``` +use Method::*; +enum Method { GET, POST } +``` "##, E0267: r##" @@ -311,7 +315,9 @@ E0296: r##" This error indicates that the given recursion limit could not be parsed. Ensure that the value provided is a positive integer between quotes, like so: - #![recursion_limit="1000"] +``` +#![recursion_limit="1000"] +``` "##, E0297: r##" @@ -320,25 +326,27 @@ that a name will be extracted in all cases. Instead of pattern matching the loop variable, consider using a `match` or `if let` inside the loop body. For instance: - // This fails because `None` is not covered. - for Some(x) in xs { - ... - } - - // Match inside the loop instead: - for item in xs { - match item { - Some(x) => ... - None => ... - } +``` +// This fails because `None` is not covered. +for Some(x) in xs { + ... +} + +// Match inside the loop instead: +for item in xs { + match item { + Some(x) => ... + None => ... } - - // Or use `if let`: - for item in xs { - if let Some(x) = item { - ... - } +} + +// Or use `if let`: +for item in xs { + if let Some(x) = item { + ... } +} +``` "##, E0301: r##" @@ -348,11 +356,13 @@ on which the match depends in such a way, that the match would not be exhaustive. For instance, the following would not match any arm if mutable borrows were allowed: - match Some(()) { - None => { }, - option if option.take().is_none() => { /* impossible, option is `Some` */ }, - Some(_) => { } // When the previous match failed, the option became `None`. - } +``` +match Some(()) { + None => { }, + option if option.take().is_none() => { /* impossible, option is `Some` */ }, + Some(_) => { } // When the previous match failed, the option became `None`. +} +``` "##, E0302: r##" @@ -362,11 +372,13 @@ on which the match depends in such a way, that the match would not be exhaustive. For instance, the following would not match any arm if assignments were allowed: - match Some(()) { - None => { }, - option if { option = None; false } { }, - Some(_) => { } // When the previous match failed, the option became `None`. - } +``` +match Some(()) { + None => { }, + option if { option = None; false } { }, + Some(_) => { } // When the previous match failed, the option became `None`. +} +``` "##, E0303: r##" @@ -374,20 +386,22 @@ In certain cases it is possible for sub-bindings to violate memory safety. Updates to the borrow checker in a future version of Rust may remove this restriction, but for now patterns must be rewritten without sub-bindings. - // Code like this... - match Some(5) { - ref op_num @ Some(num) => ... - None => ... - } - - // After. - match Some("hi".to_string()) { - Some(ref s) => { - let op_string_ref = &Some(&s); - ... - } - None => ... +``` +// Code like this... +match Some(5) { + ref op_num @ Some(num) => ... + None => ... +} + +// After. +match Some("hi".to_string()) { + Some(ref s) => { + let op_string_ref = &Some(&s); + ... } + None => ... +} +``` The `op_string_ref` binding has type &Option<&String> in both cases.