]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0211.md
Rollup merge of #92310 - ehuss:rustdoc-ice, r=estebank
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0211.md
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" {
10     fn size_of<T>(); // error: intrinsic has wrong type
11 }
12
13 // or:
14
15 fn main() -> i32 { 0 }
16 // error: main function expects type: `fn() {main}`: expected (), found i32
17
18 // or:
19
20 let x = 1u8;
21 match x {
22     0u8..=3i8 => (),
23     // error: mismatched types in range: expected u8, found i8
24     _ => ()
25 }
26
27 // or:
28
29 use std::rc::Rc;
30 struct Foo;
31
32 impl Foo {
33     fn x(self: Rc<Foo>) {}
34     // error: mismatched self type: expected `Foo`: expected struct
35     //        `Foo`, found struct `alloc::rc::Rc`
36 }
37 ```
38
39 For the first code example, please check the function definition. Example:
40
41 ```
42 #![feature(intrinsics)]
43
44 extern "rust-intrinsic" {
45     fn size_of<T>() -> usize; // ok!
46 }
47 ```
48
49 The second case example is a bit particular: the main function must always
50 have this definition:
51
52 ```compile_fail
53 fn main();
54 ```
55
56 They never take parameters and never return types.
57
58 For the third example, when you match, all patterns must have the same type
59 as the type you're matching on. Example:
60
61 ```
62 let x = 1u8;
63
64 match x {
65     0u8..=3u8 => (), // ok!
66     _ => ()
67 }
68 ```
69
70 And finally, for the last example, only `Box<Self>`, `&Self`, `Self`,
71 or `&mut Self` work as explicit self parameters. Example:
72
73 ```
74 struct Foo;
75
76 impl Foo {
77     fn x(self: Box<Foo>) {} // ok!
78 }
79 ```