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

cleanup code w/ pointers in std a little #100030

Merged
merged 3 commits into from
Aug 12, 2022

Conversation

WaffleLapkin
Copy link
Member

Use pointer methods (byte_add, null_mut, etc) to make code in std a little nicer.

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Aug 1, 2022
@rustbot

This comment was marked as resolved.

@rust-highfive
Copy link
Collaborator

r? @scottmcm

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 1, 2022
/// let x = [5u8, 6u8, 7u8, 8u8, 9u8];
/// let ptr = x.as_ptr().add(n) as *const u8;
/// let x = [5u8, 6, 7, 8, 9];
/// let ptr = x.as_ptr().add(n);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should line 1277 be cast too?

Copy link
Member

@scottmcm scottmcm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Good to do some cleanup here.

The in-code changes seem clearly good. What to do about the doc-comment feels less obvious. Up to you if you want to try to improve the doc comment more as part of this, or just leave it for the future and only do the internal changes in this PR.

@scottmcm scottmcm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 1, 2022
@WaffleLapkin
Copy link
Member Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 1, 2022
@scottmcm
Copy link
Member

scottmcm commented Aug 2, 2022

Thanks!

@bors r+

@bors
Copy link
Contributor

bors commented Aug 2, 2022

📌 Commit 6d6979b has been approved by scottmcm

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 Aug 2, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Aug 3, 2022
…cottmcm

cleanup code w/ pointers in std a little

Use pointer methods (`byte_add`, `null_mut`, etc) to make code in std a little nicer.
@matthiaskrgr
Copy link
Member

@bors r-
failed in a rollup: #100108 (comment)

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 3, 2022
@WaffleLapkin
Copy link
Member Author

It was an interesting problem:

- let is_aligned = |p| -> bool { 0 == p as usize & (Self::align_of() - 1) };
+ let is_aligned = |p| -> bool { 0 == p.addr() & (Self::align_of() - 1) };

Method resolution doesn't work with unknown types and type information doesn't really flow backwards into a closure, so a type for p can't be inferred anymore whereas it could be before. I've added an explicit type, so it should be fine now.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 5, 2022
/// } else {
/// // while the pointer can be aligned via `offset`, it would point
/// // outside the allocation
/// }
/// # } }
///
/// assert!(x == [0, 0, 7, 8, 9] || x == [5, 0, 0, 8, 9]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, one more little thing: I think this assert needs to be inside the if, because if the else block is taken then it'd fail.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@scottmcm
Copy link
Member

scottmcm commented Aug 9, 2022

Thanks! This looks good.

@bors r+

@bors
Copy link
Contributor

bors commented Aug 9, 2022

📌 Commit d52ed82 has been approved by scottmcm

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 Aug 9, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Aug 11, 2022
…cottmcm

cleanup code w/ pointers in std a little

Use pointer methods (`byte_add`, `null_mut`, etc) to make code in std a little nicer.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Aug 12, 2022
…cottmcm

cleanup code w/ pointers in std a little

Use pointer methods (`byte_add`, `null_mut`, etc) to make code in std a little nicer.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Aug 12, 2022
…cottmcm

cleanup code w/ pointers in std a little

Use pointer methods (`byte_add`, `null_mut`, etc) to make code in std a little nicer.
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 12, 2022
Rollup of 9 pull requests

Successful merges:

 - rust-lang#100022 (Optimize thread ID generation)
 - rust-lang#100030 (cleanup code w/ pointers in std a little)
 - rust-lang#100229 (add -Zextra-const-ub-checks to enable more UB checking in const-eval)
 - rust-lang#100247 (Generalize trait object generic param check to aliases.)
 - rust-lang#100255 (Adding more verbose documentation for `std::fmt::Write`)
 - rust-lang#100366 (errors: don't fail on broken primary translations)
 - rust-lang#100396 (Suggest const and static for global variable)
 - rust-lang#100409 (rustdoc: don't generate DOM element for operator)
 - rust-lang#100443 (Add two let else regression tests)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 51eed00 into rust-lang:master Aug 12, 2022
@rustbot rustbot added this to the 1.65.0 milestone Aug 12, 2022
@WaffleLapkin WaffleLapkin deleted the nice_pointer_sis branch August 19, 2022 11:53
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 2, 2022
Rollup of 7 pull requests

Successful merges:

 - rust-lang#92744 (Check if enum from foreign crate has any non exhaustive variants when attempting a cast)
 - rust-lang#99337 (rustdoc: simplify highlight.rs)
 - rust-lang#100007 (Never inline Windows dtor access)
 - rust-lang#100030 (cleanup code w/ pointers in std a little)
 - rust-lang#100192 ( Remove duplicated temporaries creating during box derefs elaboration)
 - rust-lang#100247 (Generalize trait object generic param check to aliases.)
 - rust-lang#100374 (Improve crate selection on rustdoc search results page)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
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-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants