rust icon indicating copy to clipboard operation
rust copied to clipboard

cleanup code w/ pointers in std a little

Open WaffleLapkin opened this issue 1 year ago • 7 comments

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

WaffleLapkin avatar Aug 01 '22 17:08 WaffleLapkin

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

rustbot avatar Aug 01 '22 17:08 rustbot

r? @scottmcm

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

rust-highfive avatar Aug 01 '22 17:08 rust-highfive

@rustbot ready

WaffleLapkin avatar Aug 01 '22 23:08 WaffleLapkin

Thanks!

@bors r+

scottmcm avatar Aug 02 '22 00:08 scottmcm

:pushpin: Commit 6d6979b74b14b3dead628b5014030265e5c80d09 has been approved by scottmcm

It is now in the queue for this repository.

bors avatar Aug 02 '22 00:08 bors

@bors r- failed in a rollup: https://github.com/rust-lang/rust/pull/100108#issuecomment-1204401889

matthiaskrgr avatar Aug 03 '22 20:08 matthiaskrgr

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

WaffleLapkin avatar Aug 05 '22 13:08 WaffleLapkin

Thanks! This looks good.

@bors r+

scottmcm avatar Aug 09 '22 19:08 scottmcm

:pushpin: Commit d52ed8234e8a9b8f3b988b63dae44e82827fcbda has been approved by scottmcm

It is now in the queue for this repository.

bors avatar Aug 09 '22 19:08 bors