]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0610.md
Rollup merge of #92310 - ehuss:rustdoc-ice, r=estebank
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0610.md
1 Attempted to access a field on a primitive type.
2
3 Erroneous code example:
4
5 ```compile_fail,E0610
6 let x: u32 = 0;
7 println!("{}", x.foo); // error: `{integer}` is a primitive type, therefore
8                        //        doesn't have fields
9 ```
10
11 Primitive types are the most basic types available in Rust and don't have
12 fields. To access data via named fields, struct types are used. Example:
13
14 ```
15 // We declare struct called `Foo` containing two fields:
16 struct Foo {
17     x: u32,
18     y: i64,
19 }
20
21 // We create an instance of this struct:
22 let variable = Foo { x: 0, y: -12 };
23 // And we can now access its fields:
24 println!("x: {}, y: {}", variable.x, variable.y);
25 ```
26
27 For more information about [primitives] and [structs], take a look at the Book.
28
29 [primitives]: https://doc.rust-lang.org/book/ch03-02-data-types.html
30 [structs]: https://doc.rust-lang.org/book/ch05-00-structs.html