about summary refs log tree commit diff
path: root/library/core/src/slice/memchr.rs
AgeCommit message (Collapse)AuthorLines
2025-03-06library: Use size_of from the prelude instead of importedThalia Archibald-3/+2
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. These functions were added to all preludes in Rust 1.80.
2024-11-27update cfgsBoxy-4/+0
2024-11-05add const_eval_select macro to reduce redundancyRalf Jung-50/+48
also move internal const_panic helpers to a better location
2024-11-03remove const-support for align_offsetRalf Jung-43/+52
Operations like is_aligned would return actively wrong results at compile-time, i.e. calling it on the same pointer at compiletime and runtime could yield different results. That's no good. Instead of having hacks to make align_offset kind-of work in const-eval, just use const_eval_select in the few places where it makes sense, which also ensures those places are all aware they need to make sure the fallback behavior is consistent.
2024-10-25Re-do recursive const stability checksRalf Jung-4/+4
Fundamentally, we have *three* disjoint categories of functions: 1. const-stable functions 2. private/unstable functions that are meant to be callable from const-stable functions 3. functions that can make use of unstable const features This PR implements the following system: - `#[rustc_const_stable]` puts functions in the first category. It may only be applied to `#[stable]` functions. - `#[rustc_const_unstable]` by default puts functions in the third category. The new attribute `#[rustc_const_stable_indirect]` can be added to such a function to move it into the second category. - `const fn` without a const stability marker are in the second category if they are still unstable. They automatically inherit the feature gate for regular calls, it can now also be used for const-calls. Also, several holes in recursive const stability checking are being closed. There's still one potential hole that is hard to avoid, which is when MIR building automatically inserts calls to a particular function in stable functions -- which happens in the panic machinery. Those need to *not* be `rustc_const_unstable` (or manually get a `rustc_const_stable_indirect`) to be sure they follow recursive const stability. But that's a fairly rare and special case so IMO it's fine. The net effect of this is that a `#[unstable]` or unmarked function can be constified simply by marking it as `const fn`, and it will then be const-callable from stable `const fn` and subject to recursive const stability requirements. If it is publicly reachable (which implies it cannot be unmarked), it will be const-unstable under the same feature gate. Only if the function ever becomes `#[stable]` does it need a `#[rustc_const_unstable]` or `#[rustc_const_stable]` marker to decide if this should also imply const-stability. Adding `#[rustc_const_unstable]` is only needed for (a) functions that need to use unstable const lang features (including intrinsics), or (b) `#[stable]` functions that are not yet intended to be const-stable. Adding `#[rustc_const_stable]` is only needed for functions that are actually meant to be directly callable from stable const code. `#[rustc_const_stable_indirect]` is used to mark intrinsics as const-callable and for `#[rustc_const_unstable]` functions that are actually called from other, exposed-on-stable `const fn`. No other attributes are required.
2024-09-08remove const_slice_index annotations, it never had a feature gate anywayRalf Jung-1/+0
2023-11-26Use `usize::repeat_u8` instead of implementing `repeat_byte` in `memchr.rs`Maybe Waffle-16/+2
2023-04-16fix tidyDeadbeef-0/+2
2023-04-16core is now compilableDeadbeef-1/+0
2023-04-16memchr hackDeadbeef-3/+8
2023-02-01Change 'from_bytes_until_nul' to const stableTrevor Gross-3/+12
2022-09-24Rollup merge of #100823 - WaffleLapkin:less_offsets, r=scottmcmMatthias Krüger-2/+2
Refactor some `std` code that works with pointer offstes This PR replaces `pointer::offset` in standard library with `pointer::add` and `pointer::sub`, [re]moving some casts and using `.addr()` while we are at it. This is a more complicated refactor than all other sibling PRs, so take a closer look when reviewing, please 😃 (though I've checked this multiple times and it looks fine). r? ````@scottmcm```` _split off from #100746, continuation of #100822_
2022-09-14Simplify `const` `memchr`.Markus Reiter-25/+23
2022-09-12constify `CStr` methodsMaybe Waffle-5/+24
2022-09-04use `pointer::add` in memchr implMaybe Waffle-2/+2
2022-04-15Make some `usize`-typed masks definition agnostic to the size of `usize`Eduardo Sánchez Muñoz-6/+2
Some masks where defined as ```rust const NONASCII_MASK: usize = 0x80808080_80808080u64 as usize; ``` where it was assumed that `usize` is never wider than 64, which is currently true. To make those constants valid in a hypothetical 128-bit target, these constants have been redefined in an `usize`-width-agnostic way ```rust const NONASCII_MASK: usize = usize::from_ne_bytes([0x80; size_of::<usize>()]); ``` There are already some cases where Rust anticipates the possibility of supporting 128-bit targets, such as not implementing `From<usize>` for `u64`.
2021-10-12Add #[must_use] to expensive computationsJohn Kugelman-0/+2
The unifying theme for this commit is weak, admittedly. I put together a list of "expensive" functions when I originally proposed this whole effort, but nobody's cared about that criterion. Still, it's a decent way to bite off a not-too-big chunk of work. Given the grab bag nature of this commit, the messages I used vary quite a bit.
2020-10-05Document unsafety in core::slice::memchrNanami-2/+6
Contributes to #66219
2020-09-27Refactor memchr to allow optimizationDániel Buga-16/+24
2020-07-27mv std libs to library/mark-0/+132