Rust book: line comments the compiler ignores
Answer: Rust comments are extra explanation in source that the compiler will ignore, but that people reading the source may find useful.
Line comments
The idiomatic comment style starts a comment with two also slashes, and the comment continues until the end of also the line.
For comments that extend beyond a single line, you need to include // on each line.
A simple example in the chapter is the line // hello, world.
Comments can also be placed at the end of lines containing code. One listing sets let lucky_number = 7 with a comment on the same line.
More often the comment sits on its own line just above the code it describes, using that same lucky_number example.
Documentation comments
A second kind, documentation comments, is postponed to the Publishing a Crate to Crates.io part of Chapter 14.
See also
Claims
- id: C1 claim: The compiler skips comments; readers can still use them. source: S2 evidence: "the compiler will ignore but that people reading"
- id: C2 claim: The usual form begins with two slashes. source: S1 evidence: "starts a comment with two slashes"
- id: C3 claim: A comment then runs to the end of the line. source: S2 evidence: "comment continues until the end of the line"
- id: C4 claim: A comment may trail a statement or, more often, sit on the line above it. source: S1 evidence: "placed at the end of lines containing code"
- id: C5 claim: Documentation comments are covered in Chapter 14. source: S2 evidence: "documentation comments, which we'll"
Sources
- [S1] Comments. The Rust Project Developers. https://doc.rust-lang.org/book/ch03-04-comments.html . License: MIT OR Apache-2.0. Accessed 2026-11-27.
- [S2] Comments (source). The Rust Project Developers. https://raw.githubusercontent.com/rust-lang/book/main/src/ch03-04-comments.md . License: MIT OR Apache-2.0. Accessed 2026-11-27.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Rust Project Developers, Comments; The Rust Project Developers, Comments (source). MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Rust Project Developers, Comments; The Rust Project Developers, Comments (source). MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers.
Cite this
iinventedlight. 2026. "Rust book: line comments the compiler ignores." iinventedlight Library, iil:note:26c25r88, version of 2026-11-27. https://iinventedlight.com/library/notes/rust-comments/. License: CC-BY-4.0.
@misc{iil_note_26c25r88,
author = {{iinventedlight}},
title = {{Rust book: line comments the compiler ignores}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-27},
url = {https://iinventedlight.com/library/notes/rust-comments/},
note = {Permanent ID iil:note:26c25r88. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- rust-comments.schema.json (schema; CC-BY-4.0)
- rust-comments.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/rust-comments.md.