-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mention move of individual struct fields in struct update syntax #4046
Mention move of individual struct fields in struct update syntax #4046
Conversation
This is an interesting one! I absolutely see what you’re going for, but the new text you suggested is actually getting at something substantially different from the original. Here’s code showing what the original text is trying to illustrate (playground): #[derive(Debug)]
struct User {
active: bool,
username: String,
email: String,
sign_in_count: u64,
}
fn main() {
let user1 = User {
email: String::from("[email protected]"),
username: String::from("someusername123"),
active: true,
sign_in_count: 1,
};
let user2 = User {
email: String::from("[email protected]"),
..user1
};
println!("{user1:?}"); // We cannot use the struct *as a whole*.
} We can still use individual parts of it, as your example shows, but we cannot use the struct as a whole, because parts of it have been moved out. So I think we should keep the phrase as is, but perhaps add a note after the bits about |
Oh, I see it now! I was misreading "as a whole", I understand now that it means "as a package", or "everything as a unit". Okay, I get that. I agree about adding that note. I'll give it a try writing it if you'll allow me. |
Well, there isn't much to write, actually, so I used your words. There isn't much to elaborate on, it seems, and the paragraph is already pretty dense. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼 Thanks!
Update books ## rust-lang/book 8 commits in 99cf75a5414fa8adbe3974bd0836661ca901708f..f38ce8baef98cb20229e56f1be2d50e345f11792 2024-10-07 13:21:46 UTC to 2024-09-25 22:46:26 UTC - Swap assert_eq! parameters (rust-lang/book#4058) - Add a short discussion of assignment and ownership in ch. 04 (rust-lang/book#4049) - Standardize on 'adapter', not 'adaptor' (rust-lang/book#4057) - A bit more clarity about all the stack types in 3.2 (rust-lang/book#4055) - Mention move of individual struct fields in struct update syntax (rust-lang/book#4046) - Convert ch05 to `<Listing>` (rust-lang/book#4051) - Convert ch04 to `<Listing>` (rust-lang/book#4043) - Fixed Ukrainian translation link to community repo (rust-lang/book#4039) ## rust-embedded/book 1 commits in dbae36bf3f8410aa4313b3bad42e374735d48a9d..f40a8b420ec4b4505d9489965e261f1d5c28ba23 2024-09-30 19:16:36 UTC to 2024-09-30 19:16:36 UTC - Update macOS installation instructions (rust-embedded/book#379) ## rust-lang/nomicon 1 commits in 14649f15d232d509478206ee9ed5105641aa60d0..456b904f791751892b01282fd2757904993c4c26 2024-10-05 17:29:16 UTC to 2024-10-05 17:29:16 UTC - Improve/fix description of drops (rust-lang/nomicon#465) ## rust-lang/reference 7 commits in 24fb2687cdbc54fa18ae4acf5d879cfceca77b2c..c64e52a3d306eac0129f3ad6c6d8806ab99ae2e9 2024-10-05 00:33:03 UTC to 2024-09-24 22:04:59 UTC - Fix inline-assembly documentation for LoongArch (rust-lang/reference#1644) - Explain how to name rule identifiers (rust-lang/reference#1609) - Add `expr_2021` macro fragment specifier (rust-lang/reference#1580) - Add spec identifier syntax to macro subchapters (rust-lang/reference#1625) - Authoring guide: clarify standard library linking (rust-lang/reference#1629) - Add spec identifiers to comments.md (rust-lang/reference#1563) - Add identifier syntax to visibility-and-privacy.md (rust-lang/reference#1627) ## rust-lang/rust-by-example 3 commits in c79ec345f08a1e94494cdc8c999709a90203fd88..8bede1b919a81ab7d0c961f6bbf68d3efa297bd2 2024-09-30 13:38:03 UTC to 2024-09-30 13:32:58 UTC - Minor improvements (rust-lang/rust-by-example#1888) - Clarify that the associated type is also required by the Iterator trait (rust-lang/rust-by-example#1887) - Add Chinese(zh) translation (rust-lang/rust-by-example#1886) ## rust-lang/rustc-dev-guide 34 commits in 555f3de2fa0d61c4294b74d245f1cbad6fcbf589..07bc9ca9eb1cd6d9fbbf758c2753b748804a134f 2024-10-07 15:09:03 UTC to 2024-09-24 17:49:14 UTC - rustdoc: docs for search deduplication (rust-lang/rustc-dev-guide#1850) - Revise test naming advice to discourage using issue numbers alone (rust-lang/rustc-dev-guide#2090) - Document `bootstrap` integration with `rustc-perf` (rust-lang/rustc-dev-guide#2005) - building: Update instructions for ./x setup editor (rust-lang/rustc-dev-guide#2086) - [Testing 2/2] Revise revisions docs (rust-lang/rustc-dev-guide#2089) - [Testing 1/2] Revise testing chapters excluding the directives chapter (rust-lang/rustc-dev-guide#2088) - Fixed links to rust-analyzer configs for Emacs and Helix (rust-lang/rustc-dev-guide#2087) - update `x install` documentation (rust-lang/rustc-dev-guide#2084) - Rename "object safe" to "dyn compatible" (rust-lang/rustc-dev-guide#2083) - Small follow-up to my "internal `#[rustc_*]` TEST attributes" PR (rust-lang/rustc-dev-guide#2082) - Add documentation for `{{rust-src-base}}` (rust-lang/rustc-dev-guide#2079) - building/suggested: Add instructions for Emacs & Helix (rust-lang/rustc-dev-guide#2080) - Fix file paths to section 35.1 & 35.2 example code (rust-lang/rustc-dev-guide#2078) - Clarify how to disable warnings in deps (rust-lang/rustc-dev-guide#2015) - Update compiler-src.md (rust-lang/rustc-dev-guide#1899) - Update rustdoc build instructions (rust-lang/rustc-dev-guide#1917) - Update salsa.md (rust-lang/rustc-dev-guide#1906) - Update memory.md (rust-lang/rustc-dev-guide#1907) - Update serialization.md (rust-lang/rustc-dev-guide#1909) - update rustc-driver.md (rust-lang/rustc-dev-guide#1929) - Update syntax-intro.md (rust-lang/rustc-dev-guide#1932) - Update the-parser.md (rust-lang/rustc-dev-guide#1933) - Update macro-expansion.md (rust-lang/rustc-dev-guide#1934) - Clarify a little bit in MIR chapter (rust-lang/rustc-dev-guide#1986) - Update name-resolution.md (rust-lang/rustc-dev-guide#1935) - feat: Add section about partial clones with `git clone --filter='blob:none'` (rust-lang/rustc-dev-guide#2035) - Mention rustc's stable-item-through-unstable-path bug being fixed (rust-lang/rustc-dev-guide#2064) - Fix `is_diagnostic_item()` example (rust-lang/rustc-dev-guide#2013) - Revise lldb debuginfo note wording to not imply *only* Python 3.10 can be installed (rust-lang/rustc-dev-guide#2077) - Document `crashes` test suite (rust-lang/rustc-dev-guide#2075) - Fix getting diagnostics example (rust-lang/rustc-dev-guide#2067) - Document `#[rustc_default_body_unstable]` (rust-lang/rustc-dev-guide#2065) - Describe `.git-blame-ignore-rev` (rust-lang/rustc-dev-guide#2072) - Note lldb debuginfo requires `python310.dll` to be present in `PATH` on Windows (rust-lang/rustc-dev-guide#2076)
Update books ## rust-lang/book 8 commits in 99cf75a5414fa8adbe3974bd0836661ca901708f..f38ce8baef98cb20229e56f1be2d50e345f11792 2024-10-07 13:21:46 UTC to 2024-09-25 22:46:26 UTC - Swap assert_eq! parameters (rust-lang/book#4058) - Add a short discussion of assignment and ownership in ch. 04 (rust-lang/book#4049) - Standardize on 'adapter', not 'adaptor' (rust-lang/book#4057) - A bit more clarity about all the stack types in 3.2 (rust-lang/book#4055) - Mention move of individual struct fields in struct update syntax (rust-lang/book#4046) - Convert ch05 to `<Listing>` (rust-lang/book#4051) - Convert ch04 to `<Listing>` (rust-lang/book#4043) - Fixed Ukrainian translation link to community repo (rust-lang/book#4039) ## rust-embedded/book 1 commits in dbae36bf3f8410aa4313b3bad42e374735d48a9d..f40a8b420ec4b4505d9489965e261f1d5c28ba23 2024-09-30 19:16:36 UTC to 2024-09-30 19:16:36 UTC - Update macOS installation instructions (rust-embedded/book#379) ## rust-lang/nomicon 1 commits in 14649f15d232d509478206ee9ed5105641aa60d0..456b904f791751892b01282fd2757904993c4c26 2024-10-05 17:29:16 UTC to 2024-10-05 17:29:16 UTC - Improve/fix description of drops (rust-lang/nomicon#465) ## rust-lang/reference 7 commits in 24fb2687cdbc54fa18ae4acf5d879cfceca77b2c..c64e52a3d306eac0129f3ad6c6d8806ab99ae2e9 2024-10-05 00:33:03 UTC to 2024-09-24 22:04:59 UTC - Fix inline-assembly documentation for LoongArch (rust-lang/reference#1644) - Explain how to name rule identifiers (rust-lang/reference#1609) - Add `expr_2021` macro fragment specifier (rust-lang/reference#1580) - Add spec identifier syntax to macro subchapters (rust-lang/reference#1625) - Authoring guide: clarify standard library linking (rust-lang/reference#1629) - Add spec identifiers to comments.md (rust-lang/reference#1563) - Add identifier syntax to visibility-and-privacy.md (rust-lang/reference#1627) ## rust-lang/rust-by-example 3 commits in c79ec345f08a1e94494cdc8c999709a90203fd88..8bede1b919a81ab7d0c961f6bbf68d3efa297bd2 2024-09-30 13:38:03 UTC to 2024-09-30 13:32:58 UTC - Minor improvements (rust-lang/rust-by-example#1888) - Clarify that the associated type is also required by the Iterator trait (rust-lang/rust-by-example#1887) - Add Chinese(zh) translation (rust-lang/rust-by-example#1886) ## rust-lang/rustc-dev-guide 34 commits in 555f3de2fa0d61c4294b74d245f1cbad6fcbf589..07bc9ca9eb1cd6d9fbbf758c2753b748804a134f 2024-10-07 15:09:03 UTC to 2024-09-24 17:49:14 UTC - rustdoc: docs for search deduplication (rust-lang/rustc-dev-guide#1850) - Revise test naming advice to discourage using issue numbers alone (rust-lang/rustc-dev-guide#2090) - Document `bootstrap` integration with `rustc-perf` (rust-lang/rustc-dev-guide#2005) - building: Update instructions for ./x setup editor (rust-lang/rustc-dev-guide#2086) - [Testing 2/2] Revise revisions docs (rust-lang/rustc-dev-guide#2089) - [Testing 1/2] Revise testing chapters excluding the directives chapter (rust-lang/rustc-dev-guide#2088) - Fixed links to rust-analyzer configs for Emacs and Helix (rust-lang/rustc-dev-guide#2087) - update `x install` documentation (rust-lang/rustc-dev-guide#2084) - Rename "object safe" to "dyn compatible" (rust-lang/rustc-dev-guide#2083) - Small follow-up to my "internal `#[rustc_*]` TEST attributes" PR (rust-lang/rustc-dev-guide#2082) - Add documentation for `{{rust-src-base}}` (rust-lang/rustc-dev-guide#2079) - building/suggested: Add instructions for Emacs & Helix (rust-lang/rustc-dev-guide#2080) - Fix file paths to section 35.1 & 35.2 example code (rust-lang/rustc-dev-guide#2078) - Clarify how to disable warnings in deps (rust-lang/rustc-dev-guide#2015) - Update compiler-src.md (rust-lang/rustc-dev-guide#1899) - Update rustdoc build instructions (rust-lang/rustc-dev-guide#1917) - Update salsa.md (rust-lang/rustc-dev-guide#1906) - Update memory.md (rust-lang/rustc-dev-guide#1907) - Update serialization.md (rust-lang/rustc-dev-guide#1909) - update rustc-driver.md (rust-lang/rustc-dev-guide#1929) - Update syntax-intro.md (rust-lang/rustc-dev-guide#1932) - Update the-parser.md (rust-lang/rustc-dev-guide#1933) - Update macro-expansion.md (rust-lang/rustc-dev-guide#1934) - Clarify a little bit in MIR chapter (rust-lang/rustc-dev-guide#1986) - Update name-resolution.md (rust-lang/rustc-dev-guide#1935) - feat: Add section about partial clones with `git clone --filter='blob:none'` (rust-lang/rustc-dev-guide#2035) - Mention rustc's stable-item-through-unstable-path bug being fixed (rust-lang/rustc-dev-guide#2064) - Fix `is_diagnostic_item()` example (rust-lang/rustc-dev-guide#2013) - Revise lldb debuginfo note wording to not imply *only* Python 3.10 can be installed (rust-lang/rustc-dev-guide#2077) - Document `crashes` test suite (rust-lang/rustc-dev-guide#2075) - Fix getting diagnostics example (rust-lang/rustc-dev-guide#2067) - Document `#[rustc_default_body_unstable]` (rust-lang/rustc-dev-guide#2065) - Describe `.git-blame-ignore-rev` (rust-lang/rustc-dev-guide#2072) - Note lldb debuginfo requires `python310.dll` to be present in `PATH` on Windows (rust-lang/rustc-dev-guide#2076)
Rollup merge of rust-lang#131369 - rustbot:docs-update, r=ehuss Update books ## rust-lang/book 8 commits in 99cf75a5414fa8adbe3974bd0836661ca901708f..f38ce8baef98cb20229e56f1be2d50e345f11792 2024-10-07 13:21:46 UTC to 2024-09-25 22:46:26 UTC - Swap assert_eq! parameters (rust-lang/book#4058) - Add a short discussion of assignment and ownership in ch. 04 (rust-lang/book#4049) - Standardize on 'adapter', not 'adaptor' (rust-lang/book#4057) - A bit more clarity about all the stack types in 3.2 (rust-lang/book#4055) - Mention move of individual struct fields in struct update syntax (rust-lang/book#4046) - Convert ch05 to `<Listing>` (rust-lang/book#4051) - Convert ch04 to `<Listing>` (rust-lang/book#4043) - Fixed Ukrainian translation link to community repo (rust-lang/book#4039) ## rust-embedded/book 1 commits in dbae36bf3f8410aa4313b3bad42e374735d48a9d..f40a8b420ec4b4505d9489965e261f1d5c28ba23 2024-09-30 19:16:36 UTC to 2024-09-30 19:16:36 UTC - Update macOS installation instructions (rust-embedded/book#379) ## rust-lang/nomicon 1 commits in 14649f15d232d509478206ee9ed5105641aa60d0..456b904f791751892b01282fd2757904993c4c26 2024-10-05 17:29:16 UTC to 2024-10-05 17:29:16 UTC - Improve/fix description of drops (rust-lang/nomicon#465) ## rust-lang/reference 7 commits in 24fb2687cdbc54fa18ae4acf5d879cfceca77b2c..c64e52a3d306eac0129f3ad6c6d8806ab99ae2e9 2024-10-05 00:33:03 UTC to 2024-09-24 22:04:59 UTC - Fix inline-assembly documentation for LoongArch (rust-lang/reference#1644) - Explain how to name rule identifiers (rust-lang/reference#1609) - Add `expr_2021` macro fragment specifier (rust-lang/reference#1580) - Add spec identifier syntax to macro subchapters (rust-lang/reference#1625) - Authoring guide: clarify standard library linking (rust-lang/reference#1629) - Add spec identifiers to comments.md (rust-lang/reference#1563) - Add identifier syntax to visibility-and-privacy.md (rust-lang/reference#1627) ## rust-lang/rust-by-example 3 commits in c79ec345f08a1e94494cdc8c999709a90203fd88..8bede1b919a81ab7d0c961f6bbf68d3efa297bd2 2024-09-30 13:38:03 UTC to 2024-09-30 13:32:58 UTC - Minor improvements (rust-lang/rust-by-example#1888) - Clarify that the associated type is also required by the Iterator trait (rust-lang/rust-by-example#1887) - Add Chinese(zh) translation (rust-lang/rust-by-example#1886) ## rust-lang/rustc-dev-guide 34 commits in 555f3de2fa0d61c4294b74d245f1cbad6fcbf589..07bc9ca9eb1cd6d9fbbf758c2753b748804a134f 2024-10-07 15:09:03 UTC to 2024-09-24 17:49:14 UTC - rustdoc: docs for search deduplication (rust-lang/rustc-dev-guide#1850) - Revise test naming advice to discourage using issue numbers alone (rust-lang/rustc-dev-guide#2090) - Document `bootstrap` integration with `rustc-perf` (rust-lang/rustc-dev-guide#2005) - building: Update instructions for ./x setup editor (rust-lang/rustc-dev-guide#2086) - [Testing 2/2] Revise revisions docs (rust-lang/rustc-dev-guide#2089) - [Testing 1/2] Revise testing chapters excluding the directives chapter (rust-lang/rustc-dev-guide#2088) - Fixed links to rust-analyzer configs for Emacs and Helix (rust-lang/rustc-dev-guide#2087) - update `x install` documentation (rust-lang/rustc-dev-guide#2084) - Rename "object safe" to "dyn compatible" (rust-lang/rustc-dev-guide#2083) - Small follow-up to my "internal `#[rustc_*]` TEST attributes" PR (rust-lang/rustc-dev-guide#2082) - Add documentation for `{{rust-src-base}}` (rust-lang/rustc-dev-guide#2079) - building/suggested: Add instructions for Emacs & Helix (rust-lang/rustc-dev-guide#2080) - Fix file paths to section 35.1 & 35.2 example code (rust-lang/rustc-dev-guide#2078) - Clarify how to disable warnings in deps (rust-lang/rustc-dev-guide#2015) - Update compiler-src.md (rust-lang/rustc-dev-guide#1899) - Update rustdoc build instructions (rust-lang/rustc-dev-guide#1917) - Update salsa.md (rust-lang/rustc-dev-guide#1906) - Update memory.md (rust-lang/rustc-dev-guide#1907) - Update serialization.md (rust-lang/rustc-dev-guide#1909) - update rustc-driver.md (rust-lang/rustc-dev-guide#1929) - Update syntax-intro.md (rust-lang/rustc-dev-guide#1932) - Update the-parser.md (rust-lang/rustc-dev-guide#1933) - Update macro-expansion.md (rust-lang/rustc-dev-guide#1934) - Clarify a little bit in MIR chapter (rust-lang/rustc-dev-guide#1986) - Update name-resolution.md (rust-lang/rustc-dev-guide#1935) - feat: Add section about partial clones with `git clone --filter='blob:none'` (rust-lang/rustc-dev-guide#2035) - Mention rustc's stable-item-through-unstable-path bug being fixed (rust-lang/rustc-dev-guide#2064) - Fix `is_diagnostic_item()` example (rust-lang/rustc-dev-guide#2013) - Revise lldb debuginfo note wording to not imply *only* Python 3.10 can be installed (rust-lang/rustc-dev-guide#2077) - Document `crashes` test suite (rust-lang/rustc-dev-guide#2075) - Fix getting diagnostics example (rust-lang/rustc-dev-guide#2067) - Document `#[rustc_default_body_unstable]` (rust-lang/rustc-dev-guide#2065) - Describe `.git-blame-ignore-rev` (rust-lang/rustc-dev-guide#2072) - Note lldb debuginfo requires `python310.dll` to be present in `PATH` on Windows (rust-lang/rustc-dev-guide#2076)
I would like to propose improvements to the text under the section "Creating Instances from Other Instances with Struct Update Syntax" in Chapter 5. I would welcome any improvements to the new text that I'm proposing.
When using the struct update syntax, the original struct is not invalidated: only those fields that were individually moved into the new struct.
In the original text, watch out for the emphases that I added:
It reads:
user1
as a whole: When you say "as a whole", it reads to me like the entirety of the struct has been invalidated and cannot be used anymore, which is not true. I am not a native English speaker, so please forgive me if this is just because of my poor English communication skills.user1
would still be valid: which implies thatuser1
is not valid. But it remains valid (in the sense that you can still access any fields that weren't moved), as least in the latest version of the compiler. Maybe this is a remnant from older versions?For proof, here's a Rust program (based on the examples in the book) that compiles, and runs, and outputs as expected:
Then, the following code will not compile, as expected:
This is the compiler message that I'm getting with
rustc 1.81.0 (eeb90cda1 2024-09-04)
.