]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0390.md
Rollup merge of #107190 - fmease:fix-81698, r=compiler-errors
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0390.md
1 A method or constant was implemented on a primitive type.
2
3 Erroneous code example:
4
5 ```compile_fail,E0390
6 struct Foo {
7     x: i32
8 }
9
10 impl *mut Foo {}
11 // error: cannot define inherent `impl` for primitive types
12 ```
13
14 This isn't allowed, but using a trait to implement a method or constant
15 is a good solution.
16 Example:
17
18 ```
19 struct Foo {
20     x: i32
21 }
22
23 trait Bar {
24     fn bar();
25 }
26
27 impl Bar for *mut Foo {
28     fn bar() {} // ok!
29 }
30 ```
31
32 Instead of defining an inherent implementation on a reference, you could also
33 move the reference inside the implementation:
34
35 ```compile_fail,E0390
36 struct Foo;
37
38 impl &Foo { // error: no nominal type found for inherent implementation
39     fn bar(self, other: Self) {}
40 }
41 ```
42
43 becomes
44
45 ```
46 struct Foo;
47
48 impl Foo {
49     fn bar(&self, other: &Self) {}
50 }
51 ```