Uh oh!
There was an error while loading. Please reload this page.
Constify more of alloc::Layout - #67494
Conversation
rust-highfive
commented
Dec 21, 2019
(rust_highfive has picked a reviewer for you, use r? to override) |
Centril
commented
Dec 21, 2019
r? @oli-obk |
oli-obk
left a comment
There was a problem hiding this comment.
Please file a tracking issue for this constification and use the id instead of "0"
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
lukaslueg
commented
Dec 22, 2019
I split the consttransmogrification of |
There was a problem hiding this comment.
Please make cmp::maxconst fn, too :)
There was a problem hiding this comment.
Should I file a separate tracking issue?
There was a problem hiding this comment.
sorry I missed this in the first pass
the PR lgtm after this
There was a problem hiding this comment.
Oh I just realized: std::cmp::{max; min} are defined as pub fn max<T>(v1: T, v2: T) -> T where T: Ord. There is no way to require an impl of Ord to be const?!
There was a problem hiding this comment.
Oh, no that's not possible. So leave align_to as not const fn for now, or is it super necessary?
There was a problem hiding this comment.
Not to me, no. I actually don't see this one-liner as a problem: The type is always going to be usize, so even if it never gets changed back to cmp::max(), it's totally obvious what it does.
There was a problem hiding this comment.
it's totally obvious what it does.
I agree, but
- the line of what is obvious and what not is very subjective, if at some point we have to start arguing about it, it seems good to start out conservative if there's no strong desire for the main change
- the original author must have thought that
cmp::maxis even more obvious (and I think this, too). So making code less obvious just to make it const without a strong reason to do so seems not like a good strategy.
Thanks for changing it back
There was a problem hiding this comment.
Maybe a const fn align_max(align1: usize, align2: usize) -> usize helper function to replace cmpp::max()?
(Not in this PR, it's already merged)
oli-obk
commented
Dec 22, 2019
@bors r+ |
bors
commented
Dec 22, 2019
📌 Commit b56e0e2126eaee3675805485169338d7736dd5bd has been approved by |
bors
commented
Dec 22, 2019
🌲 The tree is currently closed for pull requests below priority 100, this pull request will be tested once the tree is reopened |
lukaslueg
commented
Dec 22, 2019
I've just seen this will conflict with #66254 which does constification for just |
oli-obk
commented
Dec 22, 2019
@bors r- |
bors
commented
Dec 23, 2019
☔ The latest upstream changes (presumably #67540) made this pull request unmergeable. Please resolve the merge conflicts. |
Constify Result r? @oli-obk This is just the `Result`-part of rust-lang#67494 which I'll resubmit once rust-lang#66254 has landed.
Constify Result r? @oli-obk This is just the `Result`-part of rust-lang#67494 which I'll resubmit once rust-lang#66254 has landed.
lukaslueg
commented
Dec 31, 2019
Force-pushed a commit that wont conflict with #66254 |
CAD97
commented
Jan 9, 2020
lukaslueg
commented
Jan 10, 2020
rebased again |
bors
commented
Jan 11, 2020
☔ The latest upstream changes (presumably #68126) made this pull request unmergeable. Please resolve the merge conflicts. |
Tracking issue rust-lang#67521, Layout::new in rust-lang#66254
lukaslueg
commented
Jan 11, 2020
rebased again |
oli-obk
commented
Jan 11, 2020
@bors r+ |
bors
commented
Jan 11, 2020
📌 Commit c5a9a14 has been approved by |
bors
commented
Jan 12, 2020
⌛ Testing commit c5a9a14 with merge eb9af48328fc6dee800ed3fe2f55551322a09cd6... |
Constify more of alloc::Layout Making more methods of `alloc::Layout` const would allow us to compute alignment/size information for arbitrary (sized) types at compile-time, including placing the information in associated constants. While `mem::size_of` and `mem::align_of` are already const and `Layout` is solely based on those, there is no guarantee in the implementation that a const derived from these functions will be exactly the same as what `Layout` uses and is subsequently used in a call to `alloc::alloc`. Constifying `Layout` makes this possible. First contribution to core, excuse my ignorance.
Centril
commented
Jan 12, 2020
@bors retry rolled up. |
Rollup of 6 pull requests Successful merges: - #67494 (Constify more of alloc::Layout) - #67867 (Correctly check for opaque types in `assoc_ty_def`) - #67948 (Galloping search for binary_search_util) - #68045 (Move more of `rustc::lint` into `rustc_lint`) - #68089 (Unstabilize `Vec::remove_item`) - #68108 (Add suggestions when encountering chained comparisons) Failed merges: r? @ghost
Making more methods of
alloc::Layoutconst would allow us to compute alignment/size information for arbitrary (sized) types at compile-time, including placing the information in associated constants. Whilemem::size_ofandmem::align_ofare already const andLayoutis solely based on those, there is no guarantee in the implementation that a const derived from these functions will be exactly the same as whatLayoutuses and is subsequently used in a call toalloc::alloc. ConstifyingLayoutmakes this possible.First contribution to core, excuse my ignorance.