Skip to content

Commit

Permalink
Update E0102's example (fixes #33057)
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Apr 18, 2016
1 parent a7c3a29 commit f089cf9
Showing 1 changed file with 6 additions and 27 deletions.
33 changes: 6 additions & 27 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1420,45 +1420,24 @@ fn main() {
"##,

E0102: r##"
You hit this error because the compiler lacks information to
determine a type for this variable. Erroneous code example:
You hit this error because the compiler lacks the information to
determine the type of this variable. Erroneous code example:
```compile_fail
fn demo(devil: fn () -> !) {
let x: &_ = devil();
// error: cannot determine a type for this local variable
}
fn oh_no() -> ! { panic!("the devil is in the details") }
fn main() {
demo(oh_no);
// could be an array of anything
let x = []; // error: cannot determine a type for this local variable
}
```
To solve this situation, constrain the type of the variable.
Examples:
```no_run
```
#![allow(unused_variables)]
fn some_func(x: &u32) {
// some code
}
fn demo(devil: fn () -> !) {
let x: &u32 = devil();
// Here we defined the type at the variable creation
let x: &_ = devil();
some_func(x);
// Here, the type is determined by the function argument type
}
fn oh_no() -> ! { panic!("the devil is in the details") }
fn main() {
demo(oh_no);
let x: [u8; 0] = [];
}
```
"##,
Expand Down

0 comments on commit f089cf9

Please sign in to comment.