Skip to content

Commit

Permalink
Update diagnostics.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Apr 23, 2015
1 parent 264d365 commit 3f428cc
Showing 1 changed file with 57 additions and 43 deletions.
100 changes: 57 additions & 43 deletions src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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##"
Expand All @@ -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##"
Expand All @@ -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##"
Expand All @@ -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##"
Expand All @@ -362,32 +372,36 @@ 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##"
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.
Expand Down

0 comments on commit 3f428cc

Please sign in to comment.