about summary refs log tree commit diff
path: root/library/core/src/char
AgeCommit message (Collapse)AuthorLines
2025-09-07optimization: Don't include ASCII characters in Unicode tablesKarl Meakin-1/+37
The ASCII subset of Unicode is fixed and will never change, so we don't need to generate tables for it with every new Unicode version. This saves a few bytes of static data and speeds up `char::is_control` and `char::is_grapheme_extended` on ASCII inputs. Since the table lookup functions exported from the `unicode` module will give nonsensical errors on ASCII input (and in fact will panic in debug mode), I had to add some private wrapper methods to `char` which check for ASCII-ness first.
2025-09-03Rollup merge of #145279 - clarfonthey:const-convert-initial, r=tgross35Stuart Cook-9/+19
Constify conversion traits (part 1) This is the first part of rust-lang/rust#144289 being split into smaller pieces. It adds/moves constness of several traits under the `const_convert` feature: * `From` * `Into` * `TryFrom` * `TryInto` * `FromStr` * `AsRef` * `AsMut` * `Borrow` * `BorrowMut` * `Deref` * `DerefMut` There are a few methods that are intrinsically tied to these traits which I've included in the feature. Particularly, those which are wrappers over `AsRef`: * `ByteStr::new` (unstable under `bstr` feature) * `OsStr::new` * `Path::new` Those which directly use `Into`: * `Result::into_ok` * `Result::into_err` And those which use `Deref` and `DerefMut`: * `Pin::as_ref` * `Pin::as_mut` * `Pin::as_deref_mut` * `Option::as_deref` * `Option::as_deref_mut` * `Result::as_deref` * `Result::as_deref_mut` (note: the `Option` and `Result` methods were suggested by ``@npmccallum`` initially as rust-lang/rust#146101) The parts which are missing from this PR are: * Anything that involves heap-allocated types * Making any method const than the ones listed above * Anything that could rely on the above, *or* could rely on system-specific code for `OsStr` or `Path` (note: this mostly makes these methods useless since `str` doesn't implement `AsRef<OsStr>` yet, but it's better to track the method for now and add impls later, IMHO) r? ``@tgross35`` (who mostly already reviewed this)
2025-09-01Constify conversion traitsltdk-9/+19
2025-08-30Auto merge of #145479 - Kmeakin:km/hardcode-char-is-control, r=joboetbors-1/+5
Hard-code `char::is_control` Split off from https://github.com/rust-lang/rust/pull/145219 According to https://www.unicode.org/policies/stability_policy.html#Property_Value, the set of codepoints in `Cc` will never change. So we can hard-code the patterns to match against instead of using a table. This doesn't change the generated assembly, since the lookup table is small enough that[ LLVM is able to inline the whole search](https://godbolt.org/z/bG8dM37YG). But this does reduce the chance of regressions if LLVM's heuristics change in the future, and means less generated Rust code checked in to `unicode-data.rs`.
2025-08-26Rollup merge of #144373 - hkBst:remove-deprecated-1, r=jhprattGuillaume Gomez-17/+7
remove deprecated Error::description in impls [libs-api permission](https://github.com/rust-lang/libs-team/issues/615#issuecomment-3074045829) r? `@cuviper` or `@jhpratt`
2025-08-26remove deprecated Error::description in implsMarijn Schouten-17/+7
2025-08-17Optimize `char::encode_utf8`Karl Meakin-21/+26
Save a few instructions in `encode_utf8_raw_unchecked` by performing manual CSE.
2025-08-16refactor: Hard-code `char::is_control`Karl Meakin-1/+5
According to https://www.unicode.org/policies/stability_policy.html#Property_Value, the set of codepoints in `Cc` will never change. So we can hard-code the patterns to match against instead of using a table.
2025-08-07Optimize `char::is_alphanumeric`Karl Meakin-1/+5
Avoid an unnecessary call to `unicode::Alphabetic` when `self` is an ASCII digit (ie `0..=9`).
2025-07-21Constify Try, From, TryFromEvgenii Zheltonozhskii-5/+10
2025-06-20Add diagnostic items for ClippySamuel Tardieu-0/+1
2025-06-15Get rid of `EscapeDebugInner`.Markus Reiter-43/+19
2025-05-21Add some track_caller info to precondition panicsBen Kimock-0/+1
2025-05-16Add assert_unsafe_precondition!()s to as_ascii_unchecked() methodssam skeoch-0/+7
2025-05-16Add as_ascii_unchecked() methods to char, str, and u8sam skeoch-0/+14
2025-05-12update cfg(bootstrap)Pietro Albini-2/+2
2025-04-24Suggest {to,from}_ne_bytes for transmutations between arrays and integers, etcbendn-0/+2
2025-04-10Auto merge of #139279 - BoxyUwU:bump-boostrap, r=jieyouxubors-2/+2
Bump boostrap compiler to new beta try-job: `*msvc*`
2025-04-09replace version placeholderBoxy-2/+2
2025-04-09Speed up `String::push` and `String::insert`lincot-30/+62
Improve performance of `String` methods by avoiding unnecessary memcpy for the character bytes, with added codegen check to ensure compliance.
2025-03-16Rollup merge of #138082 - thaliaarchi:slice-cfg-not-test, r=thomcc许杰友 Jieyou Xu (Joe)-1/+1
Remove `#[cfg(not(test))]` gates in `core` These gates are unnecessary now that unit tests for `core` are in a separate package, `coretests`, instead of in the same files as the source code. They previously prevented the two `core` versions from conflicting with each other.
2025-03-07Auto merge of #138155 - matthiaskrgr:rollup-xq5buio, r=matthiaskrgrbors-12/+4
Rollup of 6 pull requests Successful merges: - #137674 (Enable `f16` for LoongArch) - #138034 (library: Use `size_of` from the prelude instead of imported) - #138060 (Revert #138019 after further discussion about how hir-pretty printing should work) - #138073 (Break critical edges in inline asm before code generation) - #138107 (`librustdoc`: clippy fixes) - #138111 (Use `default_field_values` for `rustc_errors::Context`, `rustc_session::config::NextSolverConfig` and `rustc_session::config::ErrorOutputType`) r? `@ghost` `@rustbot` modify labels: rollup
2025-03-06library: Use size_of from the prelude instead of importedThalia Archibald-12/+4
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.
2025-03-06stabilize const_char_classifyRalf Jung-2/+2
2025-03-06Remove #[cfg(not(test))] gates in coreThalia Archibald-1/+1
These gates are unnecessary now that unit tests for `core` are in a separate package, `coretests`, instead of in the same files as the source code. They previously prevented the two `core` versions from conflicting with each other.
2025-02-19Rollup merge of #120580 - HTGAzureX1212:HTGAzureX1212/issue-45795, r=m-ou-seMatthias Krüger-0/+20
Add `MAX_LEN_UTF8` and `MAX_LEN_UTF16` Constants This pull request adds the `MAX_LEN_UTF8` and `MAX_LEN_UTF16` constants as per #45795, gated behind the `char_max_len` feature. The constants are currently applied in the `alloc`, `core` and `std` libraries.
2025-02-18add last std diagnostic items for clippycyrgani-0/+1
2025-02-16add MAX_LEN_UTF8 and MAX_LEN_UTF16 constantsHTGAzureX1212-0/+20
2025-01-31Update encode_utf16 to mention it is native endianMarijn Schouten-3/+3
2024-12-31char to_digit: avoid unnecessary casts to u64Marcondiro-7/+11
2024-11-27update cfgsBoxy-5/+0
2024-11-27replace placeholder versionBoxy-4/+4
2024-11-14Auto merge of #132709 - programmerjake:optimize-charto_digit, r=joshtriplettbors-13/+31
optimize char::to_digit and assert radix is at least 2 approved by t-libs: https://github.com/rust-lang/libs-team/issues/475#issuecomment-2457858458 let me know if this needs an assembly test or similar.
2024-11-12stabilize const_unicode_case_lookupRalf Jung-4/+2
2024-11-06optimize char::to_digit and assert radix is at least 2Jacob Lifshay-13/+31
approved by t-libs: https://github.com/rust-lang/libs-team/issues/475#issuecomment-2457858458
2024-11-06Auto merge of #132500 - RalfJung:char-is-whitespace-const, r=jhprattbors-2/+3
make char::is_whitespace unstably const I am adding this to the existing https://github.com/rust-lang/rust/issues/132241 feature gate, since `is_digit` and `is_whitespace` seem similar enough that one can group them together.
2024-11-05Auto merge of #132661 - matthiaskrgr:rollup-npytbl6, r=matthiaskrgrbors-1/+1
Rollup of 8 pull requests Successful merges: - #132259 (rustc_codegen_llvm: Add a new 'pc' option to branch-protection) - #132409 (CI: switch 7 linux jobs to free runners) - #132498 (Suggest fixing typos and let bindings at the same time) - #132524 (chore(style): sync submodule exclusion list between tidy and rustfmt) - #132567 (Properly suggest `E::assoc` when we encounter `E::Variant::assoc`) - #132571 (add const_eval_select macro to reduce redundancy) - #132637 (Do not filter empty lint passes & re-do CTFE pass) - #132642 (Add documentation on `ast::Attribute`) r? `@ghost` `@rustbot` modify labels: rollup
2024-11-05add const_eval_select macro to reduce redundancyRalf Jung-1/+1
also move internal const_panic helpers to a better location
2024-11-04Stabilise 'const_char_encode_utf16';Gabriel Bjørnager Jensen-2/+5
2024-11-03Auto merge of #132542 - RalfJung:const_panic, r=tgross35bors-24/+19
add const_panic macro to make it easier to fall back to non-formatting panic in const Suggested by `@tgross35` r? `@tgross35`
2024-11-03add const_panic macro to make it easier to fall back to non-formatting panic ↵Ralf Jung-24/+19
in const
2024-11-03Auto merge of #132458 - RalfJung:rustc-const-unstable, r=Amanieubors-1/+0
get rid of a whole bunch of unnecessary rustc_const_unstable attributes In general, when a `const fn` is still unstable, it doesn't need a `#[rustc_const_unstable]` attribute. The only exception is functions that internally use things that can't be used in stable const fn yet. So this gets rid of a whole bunch of `#[rustc_const_unstable]` in libcore.
2024-11-02make char::is_whitespace unstably constRalf Jung-2/+3
2024-11-02get rid of a whole bunch of unnecessary rustc_const_unstable attributesRalf Jung-1/+0
2024-11-02fix some stability annotationsLukas Markeffsky-1/+1
2024-10-27Support `char::is_digit` in const contextsultrabear-1/+2
2024-10-25Re-do recursive const stability checksRalf Jung-1/+1
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-10-15update bootstrap configsJosh Stone-4/+0
2024-10-15replace placeholder versionJosh Stone-3/+3
(cherry picked from commit 567fd9610cbfd220844443487059335d7e1ff021)
2024-10-14Stabilise 'const_make_ascii'Gabriel Bjørnager Jensen-2/+4