Skip to content

Commit a01f956

Browse files
authored
Rollup merge of rust-lang#67422 - GuillaumeGomez:cleanup-err-codes, r=Dylan-DPC
Cleanup err codes r? @Dylan-DPC
2 parents 6e3b1d6 + dce0f06 commit a01f956

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

src/librustc_error_codes/error_codes/E0120.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
An attempt was made to implement Drop on a trait, which is not allowed: only
2-
structs and enums can implement Drop. An example causing this error:
1+
Drop was implemented on a trait, which is not allowed: only structs and
2+
enums can implement Drop.
3+
4+
Erroneous code example:
35

46
```compile_fail,E0120
57
trait MyTrait {}
@@ -10,7 +12,7 @@ impl Drop for MyTrait {
1012
```
1113

1214
A workaround for this problem is to wrap the trait up in a struct, and implement
13-
Drop on that. An example is shown below:
15+
Drop on that:
1416

1517
```
1618
trait MyTrait {}
@@ -22,7 +24,7 @@ impl <T: MyTrait> Drop for MyWrapper<T> {
2224
2325
```
2426

25-
Alternatively, wrapping trait objects requires something like the following:
27+
Alternatively, wrapping trait objects requires something:
2628

2729
```
2830
trait MyTrait {}
+19-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
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 within 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
```

0 commit comments

Comments
 (0)