Skip to content

Commit 5f2099d

Browse files
Add more details and examples in error code
1 parent 992bb13 commit 5f2099d

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/librustc_const_eval/diagnostics.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ fn foo(x: Empty) {
6262
However, this won't:
6363
6464
```compile_fail
65-
enum Empty {}
66-
6765
fn foo(x: Option<String>) {
6866
match x {
6967
// empty
@@ -191,7 +189,7 @@ inner `String` to be moved into a variable called `s`.
191189
let x = Some("s".to_string());
192190
193191
match x {
194-
op_string @ Some(s) => {},
192+
op_string @ Some(s) => {}, // error: cannot bind by-move with sub-bindings
195193
None => {},
196194
}
197195
```
@@ -288,7 +286,8 @@ struct X { x: (), }
288286
289287
let x = Some((X { x: () }, X { x: () }));
290288
match x {
291-
Some((y, ref z)) => {},
289+
Some((y, ref z)) => {}, // error: cannot bind by-move and by-ref in the
290+
// same pattern
292291
None => panic!()
293292
}
294293
```
@@ -574,6 +573,12 @@ be a compile-time constant. Erroneous code example:
574573
let x = [0i32; len]; // error: expected constant integer for repeat count,
575574
// found variable
576575
```
576+
577+
Working example:
578+
579+
```
580+
let x = [0i32; 10];
581+
```
577582
"##,
578583

579584
}

src/librustc_typeck/diagnostics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ Matching with the wrong number of fields has no sensible interpretation:
4545
4646
```compile_fail
4747
enum Fruit {
48-
Apple(String, String),
49-
Pear(u32),
48+
Fruit::Apple(String, String),
49+
Fruit::Pear(u32),
5050
}
5151
5252
let x = Fruit::Apple(String::new(), String::new());
@@ -77,8 +77,8 @@ enum Number {
7777
7878
// Assuming x is a Number we can pattern match on its contents.
7979
match x {
80-
Zero(inside) => {},
81-
One(inside) => {},
80+
Number::Zero(inside) => {},
81+
Number::One(inside) => {},
8282
}
8383
```
8484

0 commit comments

Comments
 (0)