Rollup merge of #33584 - GuillaumeGomez:error_code_improvements, r=steveklabnik

Add more details and examples in error codes

r? @steveklabnik
This commit is contained in:
Manish Goregaokar 2016-05-15 20:13:42 +05:30
commit 65814df26b
2 changed files with 13 additions and 8 deletions

View File

@ -62,8 +62,6 @@ fn foo(x: Empty) {
However, this won't:
```compile_fail
enum Empty {}
fn foo(x: Option<String>) {
match x {
// empty
@ -191,7 +189,7 @@ enum Terminator {
let x = Some("s".to_string());
match x {
op_string @ Some(s) => {},
op_string @ Some(s) => {}, // error: cannot bind by-move with sub-bindings
None => {},
}
```
@ -288,7 +286,8 @@ struct X { x: (), }
let x = Some((X { x: () }, X { x: () }));
match x {
Some((y, ref z)) => {},
Some((y, ref z)) => {}, // error: cannot bind by-move and by-ref in the
// same pattern
None => panic!()
}
```
@ -574,6 +573,12 @@ enum Method { GET, POST }
let x = [0i32; len]; // error: expected constant integer for repeat count,
// found variable
```
Working example:
```
let x = [0i32; 10];
```
"##,
}

View File

@ -45,8 +45,8 @@ enum Fruit {
```compile_fail
enum Fruit {
Apple(String, String),
Pear(u32),
Fruit::Apple(String, String),
Fruit::Pear(u32),
}
let x = Fruit::Apple(String::new(), String::new());
@ -77,8 +77,8 @@ enum Number {
// Assuming x is a Number we can pattern match on its contents.
match x {
Zero(inside) => {},
One(inside) => {},
Number::Zero(inside) => {},
Number::One(inside) => {},
}
```