Commit Graph

160 Commits

Author SHA1 Message Date
JirCep f840da757f WS fix. 2024-04-27 17:18:25 +02:00
JirCep 825a3b1f09 String.truncate calls Vec.truncate, in turn, and that states
"is greater or equal to". Beside common sense.
2024-04-27 16:57:20 +02:00
bors 4d570eea02 Auto merge of #123909 - dtolnay:utf8chunks, r=joboet
Stabilize `Utf8Chunks`

Pending FCP in https://github.com/rust-lang/rust/issues/99543.

This PR includes the proposed modification in https://github.com/rust-lang/libs-team/issues/190 as agreed in https://github.com/rust-lang/rust/issues/99543#issuecomment-2050406568.
2024-04-26 17:41:24 +00:00
David Tolnay 61cf00464e Stabilize Utf8Chunks 2024-04-24 15:27:47 -07:00
Matthias Krüger 21deaed4a1 Rollup merge of #122201 - coolreader18:doc-clone_from, r=dtolnay
Document overrides of `clone_from()` in core/std

As mentioned in https://github.com/rust-lang/rust/pull/96979#discussion_r1379502413

Specifically, when an override doesn't just forward to an inner type, document the behavior and that it's preferred over simply assigning a clone of source. Also, change instances where the second parameter is "other" to "source".

I reused some of the wording over and over for similar impls, but I'm not sure that the wording is actually *good*. Would appreciate feedback about that.

Also, now some of these seem to provide pretty specific guarantees about behavior (e.g. will reuse the exact same allocation iff the len is the same), but I was basing it off of the docs for [`Box::clone_from`](https://doc.rust-lang.org/1.75.0/std/boxed/struct.Box.html#method.clone_from-1) - I'm not sure if providing those strong guarantees is actually good or not.
2024-04-17 18:01:37 +02:00
Jani Mustonen 418535b798 doc: mention heap allocation earlier in String docs
Just a tiny addition.

Helps with #123263.
2024-04-01 00:04:57 +03:00
Matthias Krüger 0029a11d7d Rollup merge of #122835 - compiler-errors:deref-pure, r=Nadrieril
Require `DerefMut` and `DerefPure` on `deref!()` patterns when appropriate

Waiting on the deref pattern syntax pr to merge

r? nadrieril
2024-03-26 21:23:48 +01:00
Michael Goulet b56279569b Require DerefPure for patterns 2024-03-25 19:39:45 -04:00
Reed 58e2ad3d58 Amended wording 2024-03-24 12:20:39 -07:00
Reed 7b3ef13146 Fix a typo in the alloc::string::String docs 2024-03-18 11:39:00 -07:00
Noa c0e913fdd7 Document overrides of clone_from()
Specifically, when an override doesn't just forward to an inner type,
document the behavior and that it's preferred over simply assigning
a clone of source. Also, change instances where the second parameter is
"other" to "source".
2024-03-08 12:27:24 -06:00
Kornel 78fb977d6b try_with_capacity for Vec, VecDeque, String
#91913
2024-03-01 18:24:02 +00:00
Jacob Pratt 6d865038a5 Rollup merge of #120291 - pitaj:string-sliceindex, r=Amanieu
Have `String` use `SliceIndex` impls from `str`

This PR simplifies the implementation of `Index` and `IndexMut` on `String`, and in the process enables indexing `String` by any user types that implement `SliceIndex<str>`.

Similar to #47832

r? libs

Not sure if this warrants a crater run.
2024-02-29 05:25:26 -05:00
Peter Jaszkowiak 5d59d0c7d7 have String use SliceIndex impls from str 2024-02-27 09:41:32 -07:00
许杰友 Jieyou Xu (Joe) bfeea294cc Document args returned from String::into_raw_parts 2024-02-26 19:32:32 +00:00
许杰友 Jieyou Xu (Joe) 26bdf2900a Rearrange String::from_raw_parts doc argument order to match code argument order 2024-02-26 19:32:26 +00:00
Esteban Küber 0e89465672 On type error of method call arguments, look at confusables for suggestion 2024-02-22 18:04:55 +00:00
Esteban Küber e5b3c7ef14 Add rustc_confusables annotations to some stdlib APIs
Help with common API confusion, like asking for `push` when the data structure really has `append`.

```
error[E0599]: no method named `size` found for struct `Vec<{integer}>` in the current scope
  --> $DIR/rustc_confusables_std_cases.rs:17:7
   |
LL |     x.size();
   |       ^^^^
   |
help: you might have meant to use `len`
   |
LL |     x.len();
   |       ~~~
help: there is a method with a similar name
   |
LL |     x.resize();
   |       ~~~~~~
```

#59450
2024-02-22 18:04:55 +00:00
Ali MJ Al-Nasrawy 38654ad741 Rollup merge of #95967 - CAD97:from-utf16, r=dtolnay
Add explicit-endian String::from_utf16 variants

This adds the following APIs under `feature(str_from_utf16_endian)`:

```rust
impl String {
    pub fn from_utf16le(v: &[u8]) -> Result<String, FromUtf16Error>;
    pub fn from_utf16le_lossy(v: &[u8]) -> String;
    pub fn from_utf16be(v: &[u8]) -> Result<String, FromUtf16Error>;
    pub fn from_utf16be_lossy(v: &[u8]) -> String;
}
```

These are versions of `String::from_utf16` that explicitly take [UTF-16LE and UTF-16BE](https://unicode.org/faq/utf_bom.html#gen7). Notably, we can do better than just the obvious `decode_utf16(v.array_chunks::<2>().copied().map(u16::from_le_bytes)).collect()` in that:

- We handle the case where the byte slice is not an even number of bytes, and
- In the case that the UTF-16 is native endian and the slice is aligned, we can forward to `String::from_utf16`.

If the Unicode Consortium actively defines how to handle character replacement when decoding a UTF-16 bytestream with a trailing odd byte, I was unable to find reference. However, the behavior implemented here is fairly self-evidently correct: replace the single errant byte with the replacement character.
2023-10-11 03:53:16 +03:00
Jason Newcomb d464b72970 Add more diagnostic items for clippy 2023-10-05 18:21:47 -04:00
Christopher Durham 5facc32e22 fix char imports 2023-09-29 00:04:57 -04:00
Christopher Durham 1efea31385 add str_from_utf16_endian tracking issue 2023-09-28 23:56:27 -04:00
Christopher Durham 3d448bd067 style nits
Co-authored-by: David Tolnay <dtolnay@gmail.com>
2023-09-28 23:56:10 -04:00
CAD97 8047f8fb51 Add feature(str_from_utf16_endian) 2023-09-28 23:54:38 -04:00
Tshepang Mbambo e47cd2f250 string.rs: remove "Basic usage" text
Only a single example is given
2023-08-02 11:17:57 +02:00
Frank Steffahn 3911a63b77 Hide ToString implementations that specialize the default ones
The status quo is highly confusing, since the overlap is not apparent,
and specialization is not a feature of Rust. This addresses #87545;
I'm not certain if it closes it, since that issue might also be trackign
a *general* solution for hiding specializing impls automatically.
2023-07-24 23:37:35 +09:00
Andrew Tribick 2c145982a5 Demonstrate multibyte character removal in String::pop and String::remove doctests 2023-07-21 23:40:55 +02:00
Mark Rousskov 0d93d787ba Replace version placeholder to 1.72 2023-07-12 21:24:05 -04:00
Matthias Krüger b8f71eaf01 Rollup merge of #109814 - est31:stabilize_string_leak, r=Amanieu
Stabilize String::leak

Stabilizes the following API:

```Rust
impl String {
    pub fn leak(self) -> &'static mut str;
}
```

closes #102929

blocked by having an FCP for stabilization.
2023-06-14 18:10:28 +02:00
Mark Rousskov 4f9b394c8a Swap out CURRENT_RUSTC_VERSION to 1.71.0 2023-05-30 07:54:29 -04:00
est31 3ab0d90b7e Stabilize String::leak 2023-05-28 12:26:30 +02:00
Matthias Krüger 5a4c04cc2c Rollup merge of #111656 - finnbear:string_leak_unbounded_lifetime, r=Amanieu
Use an unbounded lifetime in `String::leak`.

Using `'a` instead of `'static` is predicted to make the process of making `String` generic over an allocator easier/less of a breaking change.

See:
- https://github.com/rust-lang/rust/pull/109814#issuecomment-1550164195
- https://github.com/rust-lang/rust/pull/109814#issuecomment-1550250163

ACP: https://github.com/rust-lang/libs-team/issues/109
2023-05-27 20:40:29 +02:00
Dylan DPC e0991b7bcd Rollup merge of #111168 - DaniPopes:arguments-to-string, r=Mark-Simulacrum
Specialize ToString implementation for fmt::Arguments

Generates far fewer instructions by formatting into a String with `fmt::format` directly instead of going through the `fmt::Display` impl. This change is insta-stable.
2023-05-18 10:52:34 +05:30
Finn Bear f0c9c1eb19 Use an unbounded lifetime in String::leak. 2023-05-16 13:39:17 -07:00
bors ea0c22ea4f Auto merge of #106621 - ozkanonur:enable-elided-lifetimes-for-doctests, r=Mark-Simulacrum
enable `rust_2018_idioms` lint group for doctests

With this change, `rust_2018_idioms` lint group will be enabled for compiler/libstd doctests.

Resolves #106086
Resolves #99144

Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-05-08 04:50:28 +00:00
ozkanonur 4e7c14fe9f enable rust_2018_idioms for doctests
Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-05-07 00:12:29 +03:00
Scott McMurray 8c781b0906 Add the basic ascii::Char type 2023-05-03 22:09:33 -07:00
DaniPopes fd80ab7f13 Specialize ToString implementation for fmt::Arguments 2023-05-04 00:43:17 +02:00
Deadbeef 76dbe29104 rm const traits in libcore 2023-04-16 06:49:27 +00:00
KaDiWa ad2b34d0e3 remove some unneeded imports 2023-04-12 19:27:18 +02:00
Konrad Borowski 279f35ce50 Derive String's PartialEq implementation 2023-04-05 20:58:21 +02:00
Konrad Borowski e248d0c837 Remove manual implementation of String::ne 2023-03-02 16:32:23 +01:00
bors adb4bfd25d Auto merge of #105671 - lukas-code:depreciate-char, r=scottmcm
Use associated items of `char` instead of freestanding items in `core::char`

The associated functions and constants on `char` have been stable since 1.52 and the freestanding items have soft-deprecated since 1.62 (https://github.com/rust-lang/rust/pull/95566). This PR ~~marks them as "deprecated in future", similar to the integer and floating point modules (`core::{i32, f32}` etc)~~ replaces all uses of `core::char::*` with `char::*` to prepare for future deprecation of `core::char::*`.
2023-02-12 11:09:06 +00:00
Danilo Bargen 4f36673e15 Docs: Fix format of headings in String::reserve 2023-02-07 21:32:28 +01:00
Mark Rousskov 3653254f91 Set version placeholders to 1.68 2023-01-25 09:44:29 -05:00
Lukas Markeffsky 76e216f29b Use associated items of char instead of freestanding items in core::char 2023-01-14 11:58:41 +01:00
Ezra Shaw 203bbfa2f7 impl: specialize impl of ToString on bool 2023-01-10 15:34:21 +13:00
jonathanCogan db47071df2 Replace libstd, libcore, liballoc in line comments. 2022-12-30 14:00:42 +01:00
Pietro Albini 11191279b7 Update bootstrap cfg 2022-12-28 09:18:43 -05:00
Deadbeef 64a17a09a8 Rm diagnostic item, use lang item 2022-11-18 06:16:20 +00:00