File tree Expand file tree Collapse file tree 1 file changed +19
-5
lines changed
src/librustc_error_codes/error_codes Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Original file line number Diff line number Diff line change 1- In order to be consistent with Rust's lack of global type inference,
2- type and const placeholders are disallowed by design in item signatures.
1+ The type placeholder ` _ ` was used withing a type on an item's signature.
32
4- Examples of this error include :
3+ Erroneous code example :
54
65``` compile_fail,E0121
7- fn foo() -> _ { 5 } // error, explicitly write out the return type instead
6+ fn foo() -> _ { 5 } // error
87
9- static BAR: _ = "test"; // error, explicitly write out the type instead
8+ static BAR: _ = "test"; // error
9+ ```
10+
11+ In those cases, you need to provide the type explicitly:
12+
13+ ```
14+ fn foo() -> i32 { 5 } // ok!
15+
16+ static BAR: &str = "test"; // ok!
17+ ```
18+
19+ The type placeholder ` _ ` can be used outside item's signature as follows:
20+
21+ ```
22+ let x = "a4a".split('4')
23+ .collect::<Vec<_>>(); // No need to precise the Vec's generic type.
1024```
You can’t perform that action at this time.
0 commit comments