]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0615.md
Rollup merge of #92310 - ehuss:rustdoc-ice, r=estebank
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0615.md
1 Attempted to access a method like a field.
2
3 Erroneous code example:
4
5 ```compile_fail,E0615
6 struct Foo {
7     x: u32,
8 }
9
10 impl Foo {
11     fn method(&self) {}
12 }
13
14 let f = Foo { x: 0 };
15 f.method; // error: attempted to take value of method `method` on type `Foo`
16 ```
17
18 If you want to use a method, add `()` after it:
19
20 ```
21 # struct Foo { x: u32 }
22 # impl Foo { fn method(&self) {} }
23 # let f = Foo { x: 0 };
24 f.method();
25 ```
26
27 However, if you wanted to access a field of a struct check that the field name
28 is spelled correctly. Example:
29
30 ```
31 # struct Foo { x: u32 }
32 # impl Foo { fn method(&self) {} }
33 # let f = Foo { x: 0 };
34 println!("{}", f.x);
35 ```