]> git.proxmox.com Git - rustc.git/blob - src/librustc_error_codes/error_codes/E0118.md
New upstream version 1.41.1+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0118.md
1 An inherent implementation was defined for something which isn't a struct nor
2 an enum.
3
4 Erroneous code example:
5
6 ```compile_fail,E0118
7 impl (u8, u8) { // error: no base type found for inherent implementation
8 fn get_state(&self) -> String {
9 // ...
10 }
11 }
12 ```
13
14 To fix this error, please implement a trait on the type or wrap it in a struct.
15 Example:
16
17 ```
18 // we create a trait here
19 trait LiveLongAndProsper {
20 fn get_state(&self) -> String;
21 }
22
23 // and now you can implement it on (u8, u8)
24 impl LiveLongAndProsper for (u8, u8) {
25 fn get_state(&self) -> String {
26 "He's dead, Jim!".to_owned()
27 }
28 }
29 ```
30
31 Alternatively, you can create a newtype. A newtype is a wrapping tuple-struct.
32 For example, `NewType` is a newtype over `Foo` in `struct NewType(Foo)`.
33 Example:
34
35 ```
36 struct TypeWrapper((u8, u8));
37
38 impl TypeWrapper {
39 fn get_state(&self) -> String {
40 "Fascinating!".to_owned()
41 }
42 }
43 ```