Step 5 of 6
Comments and reading compiler errors
Comments
A comment is a note for humans. The compiler ignores it.
fn main() {
// A line comment runs to the end of the line.
println!("visible"); // it can follow code, too
/* A block comment can
span several lines. */
}
visible
Programmers also "comment out" a line to switch it off for a moment without deleting it.
The compiler is on your side
Rust's compiler is famous for its error messages. They tell you what went wrong, where (file, line and column), and often how to fix it. Learning to read them is one of the most useful skills in this course. For example, this program forgets the !:
fn main() {
println("Hi!");
}
error[E0423]: cannot find function `println` in this scope
There's no function called println, only a macro. The full message points at the exact spot with ^^^^, notes that a macro named `println` exists, and adds help: use `!` to invoke the macro. When Check finds a compile error, this site shows rustc's message, a short explanation in plain English, and the line it's on in the editor.
Each error has a code like E0423. You can look up any code in the official Rust error index, or by running rustc --explain E0423.
Your task
This program has mistakes on two lines that stop it from compiling. Read the error messages after pressing Check, fix both lines, and make it print:
Errors are friends
Read them carefully
Challenge 2
Comment out the line that prints DEBUG (put // in front of it) so the program only prints Clean output. Don't delete the line.
Previous: Printing values with {} Next: Cargo: how real Rust projects are built