File tree 1 file changed +6
-27
lines changed
1 file changed +6
-27
lines changed Original file line number Diff line number Diff line change @@ -1420,45 +1420,24 @@ fn main() {
1420
1420
"## ,
1421
1421
1422
1422
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:
1425
1425
1426
1426
```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
-
1434
1427
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
1436
1430
}
1437
1431
```
1438
1432
1439
1433
To solve this situation, constrain the type of the variable.
1440
1434
Examples:
1441
1435
1442
- ```no_run
1436
+ ```
1443
1437
#![allow(unused_variables)]
1444
1438
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
-
1460
1439
fn main() {
1461
- demo(oh_no) ;
1440
+ let x: [u8; 0] = [] ;
1462
1441
}
1463
1442
```
1464
1443
"## ,
You can’t perform that action at this time.
0 commit comments