Rollup merge of #33058 - Manishearth:fx-E0102, r=GuillaumeGomez

Update E0102's example (fixes #33057)

r? @GuillaumeGomez
This commit is contained in:
Steve Klabnik 2016-04-18 14:50:35 -04:00
commit ec44ddc33a

View File

@ -1420,45 +1420,24 @@ fn main() {
"##, "##,
E0102: r##" E0102: r##"
You hit this error because the compiler lacks information to You hit this error because the compiler lacks the information to
determine a type for this variable. Erroneous code example: determine the type of this variable. Erroneous code example:
```compile_fail ```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() { 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. To solve this situation, constrain the type of the variable.
Examples: Examples:
```no_run ```
#![allow(unused_variables)] #![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() { fn main() {
demo(oh_no); let x: [u8; 0] = [];
} }
``` ```
"##, "##,