forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#67422 - GuillaumeGomez:cleanup-err-codes, r…
…=Dylan-DPC Cleanup err codes r? @Dylan-DPC
- Loading branch information
Showing
2 changed files
with
25 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,24 @@ | ||
In order to be consistent with Rust's lack of global type inference, | ||
type and const placeholders are disallowed by design in item signatures. | ||
The type placeholder `_` was used within a type on an item's signature. | ||
|
||
Examples of this error include: | ||
Erroneous code example: | ||
|
||
```compile_fail,E0121 | ||
fn foo() -> _ { 5 } // error, explicitly write out the return type instead | ||
fn foo() -> _ { 5 } // error | ||
static BAR: _ = "test"; // error, explicitly write out the type instead | ||
static BAR: _ = "test"; // error | ||
``` | ||
|
||
In those cases, you need to provide the type explicitly: | ||
|
||
``` | ||
fn foo() -> i32 { 5 } // ok! | ||
static BAR: &str = "test"; // ok! | ||
``` | ||
|
||
The type placeholder `_` can be used outside item's signature as follows: | ||
|
||
``` | ||
let x = "a4a".split('4') | ||
.collect::<Vec<_>>(); // No need to precise the Vec's generic type. | ||
``` |