liveBook · Manning

Compile time

As explained in Learn Rust in a Month of Lunches

Compile time is the phase before program execution in which source code is analyzed and transformed into executable code.

Compile time is the phase before a program starts running. During this phase, the compiler analyzes source code and reports problems while the programmer can still correct them. Rust is deliberately strict here: it moves many possible errors away from runtime debugging and gives guidance before execution. section 1.1.2

Let compiler feedback guide corrections

A small Rust program can fail at compile time because a string literal is not yet a String, push expects a char rather than a string slice, a comma is missing, or a variable is not mutable. The compiler identifies each issue and suggests corrections. Applying those suggestions produces working code, while a separate warning can flag an unused variable without preventing execution. section 1.1.2

error: expected `,`, found `my_name`
  |
4 |     println!("{}" my_name);
  |               ^^^^^^^ expected `,`
 
error[E0308]: mismatched types
 --> src/main.rs:2:27
  |
2 |     let my_name: String = "Dave";
  |                  ------   ^^^^^^- help: try using a conversion method:
                     `.to_string()`
  |                  |        |
  |                  |        expected struct `String`, found `&str`
  |                  expected due to this
 
error[E0308]: mismatched types
 --> src/main.rs:3:18
  |
3 |     my_name.push("!");
  |             ---- ^^^ expected `char`, found `&str`
  |             |
  |             arguments to this function are incorrect
  |
help: if you meant to write a `char` literal, use single quotes
  |
3 |     my_name.push('!');
  |                  ~~~

Inspect representative compiler errors and suggested fixes for types, punctuation, and character literals. section 1.1.2

How Learn Rust in a Month of Lunches covers it

How deep it goes
Explains the compile-time/runtime boundary and walks through compiler corrections, but defers detailed language rules.
Examples
Uses Rust Playground code involving String conversion, character pushing, formatting punctuation, mutability, and an unused variable.
What it assumes
Assumes only a basic distinction between source code and execution, while teaching the compile-time boundary from zero.
What you can do after
Diagnose compiler feedback and apply suggested corrections before running a Rust program.
How it connects
Connects compile time with runtime, compiler errors, warnings, type mismatches, mutability, and debugging.

Also explained in

Compare how 2 books explain compile time →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Rust in a Month of Lunches. The section links point to the parts of the book it draws on.