Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upMake `align_of` behave like `min_align_of`. #25646
Conversation
rust-highfive
assigned
brson
May 20, 2015
This comment has been minimized.
This comment has been minimized.
|
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
cc @aturon re breakage |
This comment has been minimized.
This comment has been minimized.
|
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?) |
alexcrichton
added
the
T-libs
label
May 26, 2015
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
It's not breaking because of the deprecation but because it changes the values reported by the non-deprecated stable align_of function. |
brson
added
the
I-nominated
label
Jun 1, 2015
This comment has been minimized.
This comment has been minimized.
|
Nominating this because of the breakiness. If this is important we should do it fast. |
This comment has been minimized.
This comment has been minimized.
|
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. |
alexcrichton
added
the
I-needs-decision
label
Jun 2, 2015
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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. |
Gankro
referenced this pull request
Jun 4, 2015
Closed
RFC: Allow re-exporting associated items with `use` #1150
alexcrichton
added
final-comment-period
and removed
I-needs-decision
I-nominated
labels
Jun 10, 2015
This comment has been minimized.
This comment has been minimized.
|
This PR is now entering its week-long final comment period. |
This comment has been minimized.
This comment has been minimized.
|
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: |
brson
added
regression-from-stable-to-nightly
relnotes
labels
Jun 16, 2015
This comment has been minimized.
This comment has been minimized.
alexcrichton
removed
the
final-comment-period
label
Jun 16, 2015
brson
added
the
beta-nominated
label
Jun 24, 2015
This comment has been minimized.
This comment has been minimized.
|
Nominating for backport to 1.2. Needs to be added to relnotes as a change in behavior. |
huonw
force-pushed the
huonw:align
branch
from
c168494
to
225b116
Jun 26, 2015
This comment has been minimized.
This comment has been minimized.
|
@bors r=alexcrichton |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Jun 26, 2015
This comment has been minimized.
This comment has been minimized.
bors
merged commit 225b116
into
rust-lang:master
Jun 26, 2015
huonw
referenced this pull request
Jun 26, 2015
Merged
core: fix deprecation since version of align_of_min. #26609
This comment has been minimized.
This comment has been minimized.
|
triage: beta-accepted |
huonw commentedMay 20, 2015
This removes a footgun, since it is a reasonable assumption to make that
pointers to
Twill be aligned toalign_of::<T>(). This also matchesthe behaviour of C/C++.
min_align_ofis now deprecated.Closes #21611.