-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Make align_of
behave like min_align_of
.
#25646
Conversation
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
These functions have changed so many times. How can we know this time is right? It even seems to conflict with the deleted comment 'We use the preferred alignment as the default alignment for a type. This appears to be what clang migrated towards as well'. This is a stable breaking change and should be marked as such. |
cc @aturon re breakage |
I think that the "breakage" here in this sense is fine (through deprecation), but I agree with @brson that this may want some more research into what clang is using and why (e.g. do we still match them?) |
☔ The latest upstream changes (presumably #25790) made this pull request unmergeable. Please resolve the merge conflicts. |
It's not breaking because of the deprecation but because it changes the values reported by the non-deprecated stable align_of function. |
Nominating this because of the breakiness. If this is important we should do it fast. |
I have a strong suspicion this won't cause any significant actual breakage. In fact, I suspect this change will unbreak more code than it breaks (code that was assuming that I looked through all the search results for "mem align_of" and didn't see anything where this would cause breakage. Essentially all uses of (I did notice some places in the search results which fall prey to making invalid assumptions about Unfortunately, I just realised this change still doesn't guarantee that every use std::mem;
#[repr(packed)]
struct Foo {
_x: u8,
y: u32,
}
fn main() {
let x = Foo { _x: 0, y: 0 };
println!("{}", &x.y as *const _ as usize % mem::align_of::<u32>())
} However, I think this is still an improvement: the example in #21611 seems like a footgun (there's nothing special about the struct in that example).
It seems we're currently using a different definition of preferred, e.g. clang's behaviour is what I'd expect Rust to do. |
I'm in favour of this change; basically no one on on stable could have been using this (it's only really useful for the heap::allocate API AFAICT). Everyone on unstable was wrong if they were using align_of. If they were correctly using min_align_of then they get a correct error. |
I, too, would be in favor of this to bring us in line with clang. I share @brson's concerns in that very low-level code like this often has very large ramifications later on down the road, but I'm fairly confident that those kinds of libraries have yet to be written (or are still underway), so now's definitely the time for a change like this. |
This PR is now entering its week-long final comment period. |
I feel very strongly that anything called "align-of" (with no qualifier) ought to be doing the same thing that you would get with C/C++'s Therefore: 👍 |
Nominating for backport to 1.2. Needs to be added to relnotes as a change in behavior. |
This removes a footgun, since it is a reasonable assumption to make that pointers to `T` will be aligned to `align_of::<T>()`. This also matches the behaviour of C/C++. `min_align_of` is now deprecated. Closes rust-lang#21611.
@bors r=alexcrichton |
📌 Commit 225b116 has been approved by |
This removes a footgun, since it is a reasonable assumption to make that pointers to `T` will be aligned to `align_of::<T>()`. This also matches the behaviour of C/C++. `min_align_of` is now deprecated. Closes #21611.
triage: beta-accepted |
This removes a footgun, since it is a reasonable assumption to make that
pointers to
T
will be aligned toalign_of::<T>()
. This also matchesthe behaviour of C/C++.
min_align_of
is now deprecated.Closes #21611.