diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2016-04-18 00:35:06 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2016-04-18 18:35:43 +0530 |
| commit | f089cf9b2ff2602edd989480b7cd9d4b8b820f84 (patch) | |
| tree | 1c187b77bf8ad2f1506b2f98b3b9f9366e8781be /src | |
| parent | a7c3a294bf33880d27fc7c3f662a981b1625c0bb (diff) | |
| download | rust-f089cf9b2ff2602edd989480b7cd9d4b8b820f84.tar.gz rust-f089cf9b2ff2602edd989480b7cd9d4b8b820f84.zip | |
Update E0102's example (fixes #33057)
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_typeck/diagnostics.rs | 33 |
1 files changed, 6 insertions, 27 deletions
diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 1cfbfb37d34..ed74a5166d4 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -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] = []; } ``` "##, |
