Skip to content

Commit f089cf9

Browse files
committed
Update E0102's example (fixes #33057)
1 parent a7c3a29 commit f089cf9

File tree

1 file changed

+6
-27
lines changed

1 file changed

+6
-27
lines changed

src/librustc_typeck/diagnostics.rs

+6-27
Original file line numberDiff line numberDiff line change
@@ -1420,45 +1420,24 @@ fn main() {
14201420
"##,
14211421

14221422
E0102: r##"
1423-
You hit this error because the compiler lacks information to
1424-
determine a type for this variable. Erroneous code example:
1423+
You hit this error because the compiler lacks the information to
1424+
determine the type of this variable. Erroneous code example:
14251425
14261426
```compile_fail
1427-
fn demo(devil: fn () -> !) {
1428-
let x: &_ = devil();
1429-
// error: cannot determine a type for this local variable
1430-
}
1431-
1432-
fn oh_no() -> ! { panic!("the devil is in the details") }
1433-
14341427
fn main() {
1435-
demo(oh_no);
1428+
// could be an array of anything
1429+
let x = []; // error: cannot determine a type for this local variable
14361430
}
14371431
```
14381432
14391433
To solve this situation, constrain the type of the variable.
14401434
Examples:
14411435
1442-
```no_run
1436+
```
14431437
#![allow(unused_variables)]
14441438
1445-
fn some_func(x: &u32) {
1446-
// some code
1447-
}
1448-
1449-
fn demo(devil: fn () -> !) {
1450-
let x: &u32 = devil();
1451-
// Here we defined the type at the variable creation
1452-
1453-
let x: &_ = devil();
1454-
some_func(x);
1455-
// Here, the type is determined by the function argument type
1456-
}
1457-
1458-
fn oh_no() -> ! { panic!("the devil is in the details") }
1459-
14601439
fn main() {
1461-
demo(oh_no);
1440+
let x: [u8; 0] = [];
14621441
}
14631442
```
14641443
"##,

0 commit comments

Comments
 (0)