Commit Graph

40 Commits

Author SHA1 Message Date
Jonathan Brouwer b07688dc2e Rollup merge of #153873 - folkertdev:deprecate-char-max, r=Mark-Simulacrum
deprecate `std::char` constants and functions

similar to how constants in those modules for numeric types have been deprecated. The `std::char` module contains:

Three stable constants that this PR deprecates. These already link to their associated constant equivalents.

- `MAX`
- `REPLACEMENT_CHARACTER`
- `UNICODE_VERSION`

two unstable constants that this PR removes. The constants are already stablized as associated constants on `char`.

- `MAX_LEN_UTF8`
- `MAX_LEN_UTF16`

Four stable functions that this PR deprecates. These already link to their method equivalents.

- `fn decode_utf16`
- `fn from_digit`
- `fn from_u32`
- `fn from_u32_unchecked⚠`

discussion at [#t-libs > should `std::char::{MIN, MAX}` be deprecated?](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/should.20.60std.3A.3Achar.3A.3A.7BMIN.2C.20MAX.7D.60.20be.20deprecated.3F/with/579444750).

r? libs-api
2026-04-19 16:04:32 +02:00
Jules Bertholet 8d072616a5 Add APIs for dealing with titlecase
- `char::is_cased`
- `char::is_titlecase`
- `char::case`
- `char::to_titlecase`
2026-03-21 14:30:38 -04:00
Folkert de Vries ee9b61cf75 deprecate std::char constants and functions
similar to how constants in those modules for numeric types have been deprecated
2026-03-15 11:18:22 +01:00
Markus Reiter ce457e1c26 Get rid of EscapeDebugInner. 2025-06-15 22:08:41 +02:00
lincot 09d5bcf1ad Speed up String::push and String::insert
Improve performance of `String` methods by avoiding unnecessary memcpy
for the character bytes, with added codegen check to ensure compliance.
2025-04-09 13:06:10 +03:00
HTGAzureX1212 eec49bbf59 add MAX_LEN_UTF8 and MAX_LEN_UTF16 constants 2025-02-16 21:08:38 +08:00
Lukas Markeffsky 2a6a70606d fix some stability annotations 2024-11-02 01:37:45 +01:00
Eduardo Sánchez Muñoz d4e708f1bc Remove stray dot in std::char::from_u32_unchecked documentation 2024-08-31 21:54:29 +02:00
bors f8060d282d Auto merge of #128083 - Mark-Simulacrum:bump-bootstrap, r=albertlarsan68
Bump bootstrap compiler to new beta

https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2024-07-30 17:49:08 +00:00
Nicholas Nethercote 84ac80f192 Reformat use declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00
Mark Rousskov e8644f85b8 Update CURRENT_RUSTC_VERSION 2024-07-28 14:46:29 -04:00
Nicholas Nethercote c5dadd0408 Use #[rustfmt::skip] on some use groups to prevent reordering.
`use` declarations will be reformatted in #125443. Very rarely, there is
a desire to force a group of `use` declarations together in a way that
auto-formatting will break up. E.g. when you want a single comment to
apply to a group. #126776 dealt with all of these in the codebase,
ensuring that no comments intended for multiple `use` declarations would
end up in the wrong place. But some people were unhappy with it.

This commit uses `#[rustfmt::skip]` to create these custom `use` groups
in an idiomatic way for a few of the cases changed in #126776. This
works because rustfmt treats any `use` item annotated with
`#[rustfmt::skip]` as a barrier and won't reorder other `use` items
around it.
2024-07-19 13:26:48 +10:00
Nicholas Nethercote 75b6ec9800 Avoid comments that describe multiple use items.
There are some comments describing multiple subsequent `use` items. When
the big `use` reformatting happens some of these `use` items will be
reordered, possibly moving them away from the comment. With this
additional level of formatting it's not really feasible to have comments
of this type. This commit removes them in various ways:

- merging separate `use` items when appropriate;

- inserting blank lines between the comment and the first `use` item;

- outright deletion (for comments that are relatively low-value);

- adding a separate "top-level" comment.

We also entirely skip formatting for four library files that contain
nothing but `pub use` re-exports, where reordering would be painful.
2024-07-17 08:02:46 +10:00
David Tolnay 9d3c79bcd0 Stabilize const unchecked conversion from u32 to char 2024-06-25 10:56:20 -07:00
Markus Reiter 4edf12d33e Improve escape methods. 2024-05-09 17:04:30 +02:00
Markus Reiter 16981ba406 Avoid panicking branch in EscapeIterInner. 2024-05-08 21:52:32 +02:00
Markus Reiter e3fc97be2b Inline EscapeDebug::size_hint. 2024-05-08 21:52:31 +02:00
Jules Bertholet 2f1ab2ce09 Reimplement CaseMappingIter with core::array::IntoIter
Makes the iterator 2*usize larger, but I doubt that matters much.
In exchange, we save a lot on instruction count.

In the absence of delegation syntax,
we must forward all the specialized impls manually…
2024-03-18 23:07:28 -04:00
Jules Bertholet 1c137b7582 Optimize core::char::CaseMappingIter layout
Godbolt says this saves a few instructions…
2024-03-16 23:42:06 -04:00
Markus Reiter 746a58d435 Use generic NonZero internally. 2024-02-15 08:09:42 +01:00
Scott McMurray 28449daa22 ascii::Char-ify the escaping code
This means that `EscapeIterInner::as_str` no longer needs unsafe code, because the type system ensures the internal buffer is only ASCII, and thus valid UTF-8.
2023-05-12 19:37:02 -07:00
Michal Nazarewicz 4d0f7e2f39 review 2023-04-30 03:59:11 +02:00
Michal Nazarewicz 45104397e5 Refactor core::char::EscapeDefault and co. structures
Change core::char::{EscapeUnicode, EscapeDefault and EscapeDebug}
structures from using a state machine to computing escaped sequence
upfront and during iteration just going through the characters.

This is arguably simpler since it’s easier to think about having
a buffer and start..end range to iterate over rather than thinking
about a state machine.

This also harmonises implementation of aforementioned iterators and
core::ascii::EscapeDefault struct.  This is done by introducing a new
helper EscapeIterInner struct which holds the buffer and offers simple
methods for iterating over range.

As a side effect, this probably optimises Display implementation for
those types since rather than calling write_char repeatedly, write_str
is invoked once.  On 64-bit platforms, it also reduces size of some of
the structs:

    | Struct                     | Before | After |
    |----------------------------+--------+-------+
    | core::char::EscapeUnicode  |     16 |    12 |
    | core::char::EscapeDefault  |     16 |    12 |
    | core::char::EscapeDebug    |     16 |    16 |

My ulterior motive and reason why I started looking into this is
addition of as_str method to the iterators.  With this change this
will became trivial.  It’s also going to be trivial to implement
DoubleEndedIterator if that’s ever desired.
2023-04-05 19:09:55 +02:00
Lukas Markeffsky 76e216f29b Use associated items of char instead of freestanding items in core::char 2023-01-14 11:58:41 +01:00
Pietro Albini f6762c2035 update stabilization version numbers 2022-12-28 09:18:42 -05:00
est31 176c44c08e Stabilize const_char_convert 2022-09-29 14:26:56 +02:00
est31 12c15a2bfe Split out from_u32_unchecked from const_char_convert
It relies on the Option::unwrap function which is not const-stable (yet).
2022-09-29 14:26:24 +02:00
Pietro Albini 3975d55d98 remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
Jane Losare-Lusby bf7611d55e Move error trait into core 2022-08-22 13:28:25 -07:00
Cameron Steffen 17ddcb434b Improve primitive/std docs separation and headers 2022-08-20 16:50:29 -05:00
Eduardo Sánchez Muñoz a8ff1aead8 Avoid duplication of doc comments in std::char constants and functions.
For those consts and functions, only the summary is kept and a reference to the `char` associated const/method is included.

Additionaly, re-exported functions have been converted to function definitions that call the previously re-exported function. This makes it easier to add a deprecated attribute to these functions in the future.
2022-04-01 18:36:53 +02:00
George Bateman 9aaf52b66a (#93392) Update char::MAX docs and core::char::MAX 2022-01-30 23:10:24 +00:00
Ian Douglas Scott a02639dc09 Implement TryFrom<char> for u8
Previously suggested in https://github.com/rust-lang/rfcs/issues/2854.

It makes sense to have this since `char` implements `From<u8>`. Likewise
`u32`, `u64`, and `u128` (since #79502) implement `From<char>`.
2022-01-07 12:28:47 -08:00
David Tolnay 417b6f354e Update stability attribute for double ended case mapping iterators 2021-12-22 10:49:51 -08:00
Michael Spector 83925dd453 Allow reverse iteration of lowercase'd/uppercase'd chars 2021-09-11 18:40:04 +03:00
Smitty bdfcb88e8b Use HTTPS links where possible 2021-06-23 16:26:46 -04:00
Ömer Sinan Ağacan 819247f179 Update char::escape_debug_ext to handle different escapes in strings vs. chars
Fixes #83046

The program

    fn main() {
        println!("{:?}", '"');
        println!("{:?}", "'");
    }

would previously print

    '\"'
    "\'"

With this patch it now prints:

    '"'
    "'"
2021-03-26 11:23:51 +03:00
Joshua Nelson 4d46735b8e Convert the rest of the standard library primitives to intra-doc links
Note that float methods in `core::intrinsics` weren't converted because
they are only defined in `std` (using language item hacks).
2021-02-25 20:32:49 -05:00
LeSeulArtichaut d36e3e23a8 Use intra-doc-links in core::{char, macros, fmt} 2020-08-24 00:13:23 +02:00
mark 2c31b45ae8 mv std libs to library/ 2020-07-27 19:51:13 -05:00