-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
r? @scottmcm (rust-highfive has picked a reviewer for you, use r? to override) |
library/core/src/ptr/const_ptr.rs
Outdated
/// 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); |
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.
Should line 1277 be cast
too?
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! 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.
@rustbot ready |
Thanks! @bors r+ |
…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 r- |
6d6979b
to
a7c45ec
Compare
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 @rustbot ready |
library/core/src/ptr/mut_ptr.rs
Outdated
/// } 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]); |
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.
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.
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.
done
Thanks! This looks good. @bors r+ |
…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.
…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.
…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.
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
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
Use pointer methods (
byte_add
,null_mut
, etc) to make code in std a little nicer.