← All notes

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

Sources

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

Permanent ID: iil:note:26c25r88

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.},
}

Markdown

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.

All artifact files (JSON index)

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.