Skip to content
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

Streamline deriving on packed structs. #104662

Merged

Conversation

nnethercote
Copy link
Contributor

The current approach to field accesses in derived code:

  • Normal case: &self.0
  • In a packed struct that derives Copy: &{self.0}
  • In a packed struct that doesn't derive Copy: let Self(ref x) = *self

The let pattern used in the third case is equivalent to the simpler field access in the first case. This commit changes the third case to use a field access.

The commit also combines two boolean arguments (is_packed and always_copy) into a single field (copy_fields) earlier, to save passing both around.

r? @jackh726

The current approach to field accesses in derived code:
- Normal case: `&self.0`
- In a packed struct that derives `Copy`: `&{self.0}`
- In a packed struct that doesn't derive `Copy`: `let Self(ref x) = *self`

The `let` pattern used in the third case is equivalent to the simpler
field access in the first case. This commit changes the third case to
use a field access.

The commit also combines two boolean arguments (`is_packed` and
`always_copy`) into a single field (`copy_fields`) earlier, to save
passing both around.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 21, 2022
@jackh726
Copy link
Member

LGTM. Not sure if you want to do a perf run before landing, but r=me

@nnethercote
Copy link
Contributor Author

Thanks for the fast review. I don't think this needs a perf run.

@nnethercote
Copy link
Contributor Author

@bors r=jackh726 rollup

@bors
Copy link
Contributor

bors commented Nov 21, 2022

📌 Commit a6e09a1 has been approved by jackh726

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 21, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 21, 2022
…ked-non-copy, r=jackh726

Streamline deriving on packed structs.

The current approach to field accesses in derived code:
- Normal case: `&self.0`
- In a packed struct that derives `Copy`: `&{self.0}`
- In a packed struct that doesn't derive `Copy`: `let Self(ref x) = *self`

The `let` pattern used in the third case is equivalent to the simpler field access in the first case. This commit changes the third case to use a field access.

The commit also combines two boolean arguments (`is_packed` and `always_copy`) into a single field (`copy_fields`) earlier, to save passing both around.

r? `@jackh726`
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 21, 2022
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#104420 (Fix doc example for `wrapping_abs`)
 - rust-lang#104499 (rustdoc JSON: Use `Function` everywhere and remove `Method`)
 - rust-lang#104500 (`rustc_ast`: remove `ref` patterns)
 - rust-lang#104511 (Mark functions created for `raw-dylib` on x86 with DllImport storage class)
 - rust-lang#104595 (Add `PolyExistentialPredicate` type alias)
 - rust-lang#104605 (deduplicate constant evaluation in cranelift backend)
 - rust-lang#104628 (Revert "Update CI to use Android NDK r25b")
 - rust-lang#104662 (Streamline deriving on packed structs.)
 - rust-lang#104667 (Revert formatting changes of a test)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 439a8e6 into rust-lang:master Nov 21, 2022
@rustbot rustbot added this to the 1.67.0 milestone Nov 21, 2022
@nnethercote nnethercote deleted the tweak-deriving-for-packed-non-copy branch November 21, 2022 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants