Skip to content

Fix a few statements in the Fundamentals material - #3288

Open
cindykrafft wants to merge 1 commit into
google:mainfrom
cindykrafft:fix-fundamentals-content
Open

cindykrafft wants to merge 1 commit into
google:mainfrom
cindykrafft:fix-fundamentals-content

Conversation

@cindykrafft

Copy link
Copy Markdown

Small corrections, each checked with rustc 1.94.1 (edition 2024) or against the linked source. They don't touch the files changed in open PRs (#3243, #3281–#3285).

  • borrowing/interior-mutability/refcell.md: the notes say printing a borrowed RefCell "just shows the message "{borrowed}"". With let c = RefCell::new(5); let _m = c.borrow_mut(); println!("{c:?}"); I get RefCell { value: <borrowed> }.
  • modules/encapsulation.md: #[doc_hidden] → #[doc(hidden)]. #[doc_hidden] gives "cannot find attribute doc_hidden in this scope".
  • pattern-matching/destructuring-structs.md: the notes say "Add a new field to Movement", but the struct on the slide is Move.
  • lifetimes/exercise.rs: parse_varint read at most 7 bytes, with the comment "More than 7 bytes is invalid". The protobuf encoding docs say varints use "between one and ten bytes", and that negative intN values use all ten. With the 7-byte limit, a Person with id = -1 encoded as protobuf does it (0x10 followed by ff ff ff ff ff ff ff ff ff 01) panics with "Too many bytes for varint". I changed the limit to 10. The existing tests pass, and a 10-byte varint for u64::MAX now parses. If the 7-byte limit was a deliberate simplification, I can change only the comment instead.
  • unsafe-rust/unsafe-functions/extern-c.md: "Functions declared in an extern block must be marked as safe or unsafe". The Reference says "A function declared in an extern block is implicitly unsafe unless the safe function qualifier is present", and an unqualified declaration compiles. I reworded it to "can be marked", and added that unqualified functions are unsafe to call. This may have been a deliberate simplification; please drop it if so.
  • unsafe-rust/unsafe.md: the Book's Unsafe Rust chapter is now 20.1; the ch19-01 URL redirects to ch20-01.
  • Typos: "know as" → "known as" (iterators/helpers.md), "collected in to" → "collected into" (iterators/collect.md), "into a the" → "into the" (pattern-matching/exercise.md).

cargo test, mdbook test and dprint check pass.

- RefCell: a borrowed RefCell's Debug output is
  `RefCell { value: <borrowed> }` (rustc 1.94.1), not "{borrowed}".
- Modules: the attribute is `#[doc(hidden)]`, not `#[doc_hidden]`.
- Destructuring structs: the struct on the slide is `Move`.
- Protobuf exercise: `parse_varint` stopped after 7 bytes and called
  longer varints invalid, but protobuf varints can be up to 10 bytes
  (e.g. negative int32 values). Accept up to 10 bytes.
- extern-c: functions in an `unsafe extern` block without a
  `safe`/`unsafe` qualifier compile and are unsafe to call.
- Link Unsafe Rust at chapter 20.1 of the Book (19.1 now redirects).
- Typos: "known as", "collected into", "into the".

Claude-Session: https://claude.ai/code/session_01X59fWmqnA4Nmb9rggkTP7n
@fw-immunant

Copy link
Copy Markdown
Collaborator

Hi, could you say a bit about these changes in your own words?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants