Rust compiler
The Rust compiler, usually invoked as rustc, is the official compiler for the Rust programming language. It is developed by the Rust Project and released under a dual Apache 2.0 and MIT License. rustc translates Rust source code into native machine code. It is itself written in Rust and is self-hosting: each new version is built using the previous stable release. Most developers do not call rustc directly. They use Cargo, Rust's standard build tool and package manager, which invokes the compiler with the right options for a given project. rustc is best known for two features: a type system that enforces memory and thread safety at compile time, and error messages that point at the offending source span and often suggest a fix.
The Rust compiler, usually invoked as rustc, is the official compiler for the Rust programming language. It is developed by the Rust Project and released under a dual Apache 2.0 and MIT License. rustc translates Rust source code into native machine code. It is itself written in Rust and is self-hosting: each new version is built using the previous stable release. Most developers do not call rustc directly. They use Cargo, Rust's standard build tool and package manager, which invokes the compiler with the right options for a given project. rustc is best known for two features: a type system that enforces memory and thread safety at compile time, and error messages that point at the offending source span and often suggest a fix. fn main() { println!("Hello, world!"); } The file can be compiled directly from a shell: rustc hello.rs This produces an executable named on Unix-like systems, or on Windows, using the default edition and optimisation settings. Direct invocation is useful for small experiments, compiler tests and build systems that call rustc themselves. For ordinary projects, Cargo is the usual entry point. A typical workflow creates a package, builds it, runs it, and then executes its tests: cargo new hello cd hello cargo build cargo run cargo test Cargo stores build output under , resolves dependencies from crates.io, and forwards the appropriate command-line options to rustc. [package] name = "myapp" version = "0.1.0" edition = "2021" When invoking rustc directly, the equivalent is the flag. Omitting the field falls back to the 2015 edition for backward compatibility. For Cargo-based projects, edition migration is typically guided by rustc diagnostics and . fn main() { let s = String::from("hello"); let t = s; // ownership of the String moves into `t` println!("{}", s); // error: `s` no longer owns the value } rustc rejects the program with diagnostic (borrow of moved value), pointing at the call and at the earlier line where ownership was transferred. error[E0382]: borrow of moved value: `s` --> hello.rs:4:20 | 2 | let s = String::from("hello"); | - move occurs because `s` has type `String`, | which does not implement the `Copy` trait 3 | let t = s; | - value moved here 4 | println!("{}", s); | ^ value borrowed here after move The exact wording can change between compiler releases, but the structure is stable: an error code, a primary location, secondary notes and a pointer to the span where compilation failed. [package] name = "example" version = "0.1.0" edition = "2021" [dependencies] serde = "1" [profile.release] opt-level = 3 lto = true Cargo has named profiles such as , , and . Profiles control optimisation level, debug information, link-time optimisation and related compiler options. Larger projects can also use workspaces, where a top-level table lists member crates that share one dependency lock file and build directory. rustup component add rustfmt clippy rustup target add aarch64-unknown-linux-gnu cargo build --release --target aarch64-unknown-linux-gnu A project can pin its toolchain with , which rustup reads automatically when commands run inside the project directory. [allow(clippy::needless_return)] fn answer() -> i32 { return 42; }
References
No reference rows published for this article.
Cite this article
MLA
"Rust compiler." encyclopegia.org, 2026, https://encyclopegia.org/wiki/rust-compiler. Accessed 24 November 2026.
Chicago
"Rust compiler." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/rust-compiler.
APA
encyclopegia.org. (2026). Rust compiler. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/rust-compiler
Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON