-
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
Constify pointer::is_aligned{,to}
#102753
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
24241b0
to
bfb7b27
Compare
Cc @rust-lang/wg-const-eval I am not entirely sure about this... pointers are wonky in const and this function does not behave the way people will expect it to behave. Also I think we should keep this and |
yea, it should not add a new intrinsic, but be implemented in terms of the existing one. |
the same is true for align_offset and |
I think doing that would make those interfaces more popular, people should be using the standard library instead of re-implementing these. Right now I know of a few people who specifically avoid them because of the vague caveat in the docs. If we remove that, there should be a proper announcement of the change in direction we're taking in designing pointer interfaces. And I for one would like pressure for |
Pressure doesn't help. People doing the work help. :) |
I'm on it 😆 |
I think I meant a different kind of pressure. If I can tell a compelling story, it's easy to motivate community members to pitch in. |
I've put up an alternate PR which doesn't need a new intrinsic and uses |
bfb7b27
to
c2605f6
Compare
The Miri subtree was changed cc @rust-lang/miri |
Some changes occurred in const_evaluatable.rs cc @lcnr This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras Some changes occurred in src/librustdoc/clean/types.rs cc @camelid Some changes occurred in HTML/CSS themes. Some changes occurred in compiler/rustc_codegen_gcc cc @antoyo Some changes occurred in src/tools/clippy cc @rust-lang/clippy
cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred in HTML/CSS/JS. cc @GuillaumeGomez, @Folyd, @jsha Some changes occurred in src/tools/cargo cc @ehuss
cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki Some changes occurred in need_type_info.rs cc @lcnr
cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki A change occurred in the Ayu theme. cc @Cldfire |
Whoops, sorry for the massive ping. Pushed something here that I shouldn't have. Anyway, closing this in favor of #102795. |
…lign-offset, r=oli-obk Constify `is_aligned` via `align_offset` Alternative to rust-lang#102753 Make `align_offset` work in const eval (and not always return `usize::MAX`) and then use that to constify `is_aligned{_to}`. Tracking Issue: rust-lang#104203
…et, r=oli-obk Constify `is_aligned` via `align_offset` Alternative to rust-lang/rust#102753 Make `align_offset` work in const eval (and not always return `usize::MAX`) and then use that to constify `is_aligned{_to}`. Tracking Issue: rust-lang/rust#104203
…et, r=oli-obk Constify `is_aligned` via `align_offset` Alternative to rust-lang/rust#102753 Make `align_offset` work in const eval (and not always return `usize::MAX`) and then use that to constify `is_aligned{_to}`. Tracking Issue: rust-lang/rust#104203
In this PR i've made
<*const T>::is_aligned
and<*const T>::is_aligned_to
unstably const.The main motivation here is to allow something like
debug_assert!(is_aligned_and_not_null(ptr))
inconst fn
s without anyconst_eval_select
hacks.If we don't know the address of a pointer in const eval, this function only returns
true
if we know for sure that the pointer is aligned. This means that in some cases a pointer can never be aligned, which matches the behavior ofalign_offset
1.Tracking issue for
is_aligned
: #96284Footnotes
Note that currently
align_offset
will always returnusize::MAX
in CTFE, but it could return a useful value for some alignments in the future. ↩