]>
Commit | Line | Data |
---|---|---|
60c5eb7d XL |
1 | #### Note: this error code is no longer emitted by the compiler. |
2 | ||
3 | You used a function or type which doesn't fit the requirements for where it was | |
4 | used. Erroneous code examples: | |
5 | ||
6 | ```compile_fail | |
7 | #![feature(intrinsics)] | |
8 | ||
9 | extern "rust-intrinsic" { | |
2b03887a | 10 | #[rustc_safe_intrinsic] |
60c5eb7d XL |
11 | fn size_of<T>(); // error: intrinsic has wrong type |
12 | } | |
13 | ||
14 | // or: | |
15 | ||
16 | fn main() -> i32 { 0 } | |
17 | // error: main function expects type: `fn() {main}`: expected (), found i32 | |
18 | ||
19 | // or: | |
20 | ||
21 | let x = 1u8; | |
22 | match x { | |
23 | 0u8..=3i8 => (), | |
24 | // error: mismatched types in range: expected u8, found i8 | |
25 | _ => () | |
26 | } | |
27 | ||
28 | // or: | |
29 | ||
30 | use std::rc::Rc; | |
31 | struct Foo; | |
32 | ||
33 | impl Foo { | |
34 | fn x(self: Rc<Foo>) {} | |
35 | // error: mismatched self type: expected `Foo`: expected struct | |
36 | // `Foo`, found struct `alloc::rc::Rc` | |
37 | } | |
38 | ``` | |
39 | ||
40 | For the first code example, please check the function definition. Example: | |
41 | ||
42 | ``` | |
43 | #![feature(intrinsics)] | |
44 | ||
45 | extern "rust-intrinsic" { | |
2b03887a | 46 | #[rustc_safe_intrinsic] |
60c5eb7d XL |
47 | fn size_of<T>() -> usize; // ok! |
48 | } | |
49 | ``` | |
50 | ||
51 | The second case example is a bit particular: the main function must always | |
52 | have this definition: | |
53 | ||
54 | ```compile_fail | |
55 | fn main(); | |
56 | ``` | |
57 | ||
58 | They never take parameters and never return types. | |
59 | ||
60 | For the third example, when you match, all patterns must have the same type | |
61 | as the type you're matching on. Example: | |
62 | ||
63 | ``` | |
64 | let x = 1u8; | |
65 | ||
66 | match x { | |
67 | 0u8..=3u8 => (), // ok! | |
68 | _ => () | |
69 | } | |
70 | ``` | |
71 | ||
72 | And finally, for the last example, only `Box<Self>`, `&Self`, `Self`, | |
73 | or `&mut Self` work as explicit self parameters. Example: | |
74 | ||
75 | ``` | |
76 | struct Foo; | |
77 | ||
78 | impl Foo { | |
79 | fn x(self: Box<Foo>) {} // ok! | |
80 | } | |
81 | ``` |