A compiler translates Rust source into an executable while checking types, ownership, borrowing, and references before the program runs. This turns many memory-management failures into compile-time errors. section 1.4.2 section 2.6
The compiler helps enforce several rules during development:
- Rejects programs that violate ownership rules, such as using a value after it has moved. section 2.1
- Checks that references remain valid and prevents reads from invalid memory. section 2.6
- Infers many local variable types while still enforcing static type compatibility. section 1.4.3
- Compiles an application and runs its resulting executable through Cargo. section 2.1
Catching a moved value
An artwork is passed to admire_art, transferring ownership to the function. Calling admire_art(art1) again produces error E0382 because art1 has already been moved. The compiler catches this before execution rather than allowing an invalid memory access. section 2.1 section 1.4.2
$ cargo new art-museum
Create a Rust project with Cargo before compiling and running code that the compiler can check. section 2.1








