Commit Graph

3366 Commits

Author SHA1 Message Date
Jacob Pratt
a768b8c11e Rollup merge of #156783 - MingweiSamuel:patch-2, r=jhpratt
docs: make `Rc::into_raw` clickable in `Rc::increment_strong_count` doc

adds doc link
2026-06-07 00:37:54 -04:00
Jacob Pratt
dace13273d Rollup merge of #154742 - Jules-Bertholet:casefold, r=Mark-Simulacrum
Add APIs for case folding to the standard library

[Libs-api requested these](https://github.com/rust-lang/rust/pull/154287#issuecomment-4165104865), so here they are.

New public API (gated behind `#[feature(casefold)]`):

```rust
impl char {
    pub fn to_casefold(self) -> ToCasefold;
}

impl str {
    pub fn to_casefold(&self) -> String;
    pub fn eq_ignore_case(&self) -> bool;
}

pub struct ToCasefold { ... }
impl Iterator for ToCasefold { type Item = char; ... }
impl DoubleEndedIterator for ToCasefold { ... }
impl FusedIterator for ToCasefold { }
impl ExactSizeIterator for ToCasefold { ... }
impl fmt::Display for ToCasefold { ... }
```

## Notes

- This only adds a negligible amount of static data to `core::unicode`. To accomplish that, we compute the case-folding for most characters as the lowercase of their uppercase; this double mapping adds some complexity to the implementation.
- No normalization (e.g. NFC) is performed, so visually and semantically equivalent strings can compare unequal.
- I have not put any effort into optimizing `eq_ignore_case()`; there may be a more performant implementation.
- `char::eq_ignore_case()` is left to future work—it's a potential footgun, so we may want to think more deeply about how to expose and document that API.

@rustbot label T-libs-api A-unicode
2026-06-07 00:37:45 -04:00
Jonathan Brouwer
649f1574bc Rollup merge of #157138 - Omnikar:vec-clone-doc, r=joboet
Add doc comment to `Vec::clone`

I read about Clippy's [`repeat_vec_with_capacity`](https://rust-lang.github.io/rust-clippy/rust-1.96.0/index.html#repeat_vec_with_capacity) lint and figured it was worth adding a note about the relevant behavior to the documentation of `Vec::clone` itself, which previously did not have its own doc comment.
2026-06-04 12:06:51 +02:00
Jules Bertholet
e6d5e95bc0 Revert "Use ascii::Char in convert_while_ascii"
This reverts commit 1ec2ee97cc,
which unfortunately prevented `convert_while_ascii`
from vectorizing :(

"LLVM gave, and LLVM hath taken away"
2026-06-02 09:37:44 -04:00
Jacob Pratt
5d3c4fbcd3 Rollup merge of #156832 - hanna-kruppe:consistent-strict-provenance-lints, r=jhpratt
library: use strict provenance lints consistently

The `fuzzy_provenance_casts` lint is enabled in most of the standard library, but its identical twin `lossy_provenance_casts` was not. As discussed in the tracking issue for those lints, there doesn't seem to be any good reason to enable one without the other. This PR applies this principle and as a result removes some unnecessary ptr->int `as` casts.

It's also preparation for merging the two lints, which removes the option of only enabling `fuzzy_provenance_casts`.

Tracking issue: rust-lang/rust#130351
2026-05-31 22:30:32 -04:00
Jules Bertholet
1ec2ee97cc Use ascii::Char in convert_while_ascii 2026-05-31 17:00:41 -04:00
Omnikar
aa9e76ec33 Add doc comment to Vec::clone 2026-05-31 14:20:23 -04:00
Josh Stone
4294891f47 Reformat with the new stage0 2026-05-31 06:58:19 -07:00
Jonathan Brouwer
694e1f919a Rollup merge of #156109 - Paladynee:lib/cast-slice-improvements, r=jhpratt
Migrate libraries from ptr::slice_from_raw_parts to .cast_slice

Tracking issue for `#![feature(ptr_cast_slice)]`: rust-lang/rust#149103
This commit updates most callsites of ptr::slice_from_raw_parts within ./library to the more concise but unstable postfix `.cast_slice()` method on raw pointers, using the `ptr_cast_slice` feature. Some tests in alloctests have also been updated.

No functional change, debatably improved readability.
2026-05-30 23:05:32 +02:00
Mingwei Samuel
a821b2b4a0 fix indentation 2026-05-27 08:11:22 -07:00
Mingwei Samuel
b097ed1cb3 remove explicit doc linking
Co-authored-by: Jonas Böttiger <jonasboettiger@icloud.com>
Co-authored-by: Mingwei Samuel <mingwei.samuel@gmail.com>
2026-05-27 08:10:33 -07:00
Jules Bertholet
da14011f19 Add tracking issue 2026-05-26 23:31:48 -04:00
Jules Bertholet
ee404447ba Postfix method names with _unnormalized 2026-05-26 23:31:48 -04:00
Jules Bertholet
db01ed4b3c Address review comments 2026-05-26 21:59:21 -04:00
Jules Bertholet
6584161c67 Add str::eq_ignore_case()
With an unoptimized, non-`const` implementation
for now.
2026-05-26 21:59:21 -04:00
Jules Bertholet
21a57cbd7d Add str::to_casefold() 2026-05-26 21:59:21 -04:00
Hanna Kruppe
fed6279325 library: use strict provenance lints consistently
The `fuzzy_provenance_casts` lint is enabled in most of the standard
library, but its identical twin `lossy_provenance_casts` was not. As
discussed in the tracking issue for those lints, there doesn't seem to
be any good reason to enable one without the other. This PR applies this
principle and as a result removes some unnecessary ptr->int `as` casts.

It's also preparation for merging the two lints, which removes the
option of only enabling `fuzzy_provenance_casts`.
2026-05-25 20:45:24 +02:00
Jacob Pratt
9c63e94ef7 Rollup merge of #156810 - Teufelchen1:fix_doc_typo, r=SimonSapin
Fix doc typo in Vec::into_array and convert Arc/Box/Rc::into_arry to -> Result

Hello 🪼,

the first commit fixes a documentation mistake added in the recent PR rust-lang/rust#156234

The second commit addresses three function signature changes as defined by the tracking issue rust-lang/rust#148082
It converts all `.into_array() -> Option<>` into `.into_array() -> Result<>`

The third commit is a fixup for the second. The change is needed as calling `unwrap()` on `Err(E)` requires `E` to implement `Debug`. I thought `Vec<T, A> where T: Debug` is not an acceptable solution, so I tried to come up with my own. I am *NOT* confident in my `unsafe {}`  code due to lack of expierence, please check extra carefully.

Appreciating feedback & greetings from the RustWeek,
Thanks!
2026-05-24 16:39:41 +02:00
Bennet Blischke
8b382d62df Return result instead of option by Arc/Rc/Box::into_array 2026-05-24 11:39:35 +02:00
Jonathan Brouwer
eb68b36521 Rollup merge of #156828 - P8L1:share-trait-core-bootstrap, r=SimonSapin
Add unstable Share trait

Tracking issue: rust-lang/rust#156756

This adds an initial unstable `Share` trait for clone-as-alias types, as part of the 2026 ergonomic ref-counting project goal.

```rust
pub trait Share: Clone {
    fn share(&self) -> Self {
        Clone::clone(self)
    }
}
```

This PR adds a separate unstable feature gate:

```rust
#![feature(share_trait)]
```

and places the trait next to `Clone` in `core::clone`.

Implemented initial impls:

- `impl<T: ?Sized> Share for &T`
- `impl<T: ?Sized, A: Allocator + Clone> Share for Rc<T, A>`
- `impl<T: ?Sized, A: Allocator + Clone> Share for Arc<T, A>`
- `impl<T> Share for std::sync::mpsc::Sender<T>`
- `impl<T> Share for std::sync::mpsc::SyncSender<T>`

The PR deliberately does not add `Share` to the prelude.

r? @nikomatsakis
@rustbot label F-ergonomic_clones
2026-05-24 08:27:21 +02:00
Pieter-Louis Schoeman
9b3cd578ab Remove provisional Share trait FIXME notes 2026-05-22 07:13:06 +02:00
bors
3bf5c6d99b Auto merge of #152112 - Kobzol:vec-deque-strongly-typed, r=joboet
Use strongly typed wrapped indices in `VecDeque`



This is far from perfect, but it would have prevented https://github.com/rust-lang/rust/pull/151769.

r? @joboet
2026-05-22 02:21:11 +00:00
Pieter-Louis Schoeman
78b0f9db85 Add Share impl for Arc 2026-05-22 00:11:38 +02:00
Pieter-Louis Schoeman
fc33b6d4f4 Add Share impl for Rc 2026-05-22 00:09:24 +02:00
Bennet Blischke
d9ab6d6e2d Correct doc of Vec::into_array: Returns Err(Self) instead of None 2026-05-21 18:07:22 +02:00
Mingwei Samuel
3a3155ebb6 docs: make Rc::into_raw clickable in Rc::increment_strong_count doc
adds doc link
2026-05-20 10:50:10 -07:00
Jonathan Brouwer
27d3139405 Rollup merge of #155840 - Lars-Schumann:prefer-is-zst, r=clarfonthey
prefer `T::IS_ZST` over manual check

makes the intent clearer and possible small perf improvement
2026-05-18 23:17:17 +02:00
bors
5ea817c65e Auto merge of #149696 - jnodorp:clarify-utf16-errors, r=SimonSapin
Clarify UTF-16 decoding errors

Fix UTF-16 error messages as suggested in rust-lang/rust#116258.
2026-05-18 04:49:52 +00:00
Jonathan Brouwer
acd0707333 Rollup merge of #156234 - bend-n:into_array_for_vec_t_via_boxed_array, r=SimonSapin
implement `into_array` for `Vec<T>`

for more into_array coverage and to avoid harmful obtuse opaque try_into calls
2026-05-18 03:19:46 +02:00
Lars Schumann
6eefc1b28d prefer T::IS_ZST over manual check 2026-05-17 22:52:25 +00:00
Jonathan Brouwer
845f3d30bf Rollup merge of #156556 - qaijuang:issue-156491-str-replace-utf8-pattern, r=ChrisDenton
Require UTF-8 in `Utf8Pattern::StringPattern`

Store `&str` instead, so the UTF-8 invariant is enforced at the API boundary.

Fixes rust-lang/rust#156491
2026-05-15 20:11:46 +02:00
bors
88ba7fbe0a Auto merge of #155360 - malezjaa:try_insert_changes, r=cuviper
map_try_insert changes





Made changes according to https://github.com/rust-lang/rust/issues/82766#issuecomment-4253028464.

r? @tgross35
2026-05-15 08:12:52 +00:00
Qai Juang
8909e794e7 Require UTF-8 in Utf8Pattern::StringPattern 2026-05-14 21:26:00 -04:00
malezjaa
ca70543ca4 map_try_insert changes 2026-05-14 22:36:03 +02:00
ast-ral
ed2f960d5b fix missing space in Rc::decrement_strong_count 2026-05-11 17:09:34 -07:00
bendn
d8502aa007 implement into_array for Vec<T> 2026-05-11 16:38:54 +07:00
Voxell Paladynee
cd1f62564f Migrate libraries from ptr::slice_from_raw_parts to .cast_slice 2026-05-10 19:38:42 +02:00
Jakub Beránek
aa9f27e865 Rename WrappedIndex::new to from_arbitrary_number and resolve review remarks 2026-05-10 10:11:50 +02:00
Matthias Krüger
27282040f7 Rollup merge of #155705 - Jules-Bertholet:word-to-titlecase, r=Mark-Simulacrum
Add `str::word_to_titlecase()` to `alloc`

A small addition to https://github.com/rust-lang/rust/issues/153892.

Hasn't gone through ACP, so needs libs-API signoff.

@rustbot label A-Unicode T-libs-api
2026-05-10 03:16:58 +02:00
bors
82bee96507 Auto merge of #155321 - briansmith:b/bufwriter-conservative, r=Mark-Simulacrum
`BufWriter`: Make the soundness of `BorrowedBuf` usage clearer.

The previous safety comment was outdated as it was written before `BorrowedBuf::set_init` was changed to be a boolean. It also failed to address the possibility that `flush_buf` invalidated the assumption.
2026-05-09 18:40:20 +00:00
Jules Bertholet
40da877450 Add str::word_to_titlecase() to alloc
* Add `str::word_to_titlecase()` to `alloc`
* Address review comment
2026-05-09 17:42:42 +00:00
Jakub Beránek
207d3bd5f0 Change abs_diff return type to usize 2026-05-09 11:55:38 +02:00
Jakub Beránek
e36f74d3b8 Use strongly typed wrapped indices in VecDeque 2026-05-09 11:55:37 +02:00
Oli Scherer
664177fdf1 Remove const closure hacks in libstd 2026-05-05 11:35:29 +02:00
bors
783062d3c6 Auto merge of #154095 - joboet:vec_clear_truncate, r=nnethercote
std: implement `clear` via `truncate`

This gets rid of some `unsafe`. `truncate(0)` is even documented to be equivalent to `clear`, this makes that equivalence even more obvious.
2026-05-04 06:16:32 +00:00
Brian Smith
d50c54bd53 BufWriter: Make the soundness of BorrowedBuf usage clearer.
The previous safety comment was outdated as it was written before
`BorrowedBuf::set_init` was changed to be a boolean. It also failed
to address the possibility that `flush_buf` invalidated the
assumption.

Simplify the implementation of `flush_buf` to more obviously preserve
the spare capacity, and document the need to preserve the spare
capacity where necessary.
2026-05-02 11:55:41 -07:00
Ralf Jung
e402c1edf0 miri: remove retag statements, make typed copies retag implicitly instead 2026-05-02 17:40:33 +02:00
joboet
f8b83b23c3 std: don't implement clear via truncate 2026-05-01 16:22:40 +02:00
Jacob Pratt
06fa54768c Rollup merge of #155858 - ChrisDenton:borrowed-len, r=jhpratt
`slice::join`: borrow only once during length calc

This ensures the length calculation will always be self-consistent even if the real length changes when we actually come to use them.

This is a follow up to rust-lang/rust#155708
2026-04-28 05:37:23 -04:00
Jacob Pratt
8985f1f97b Rollup merge of #155847 - DaniPopes:string-push-len, r=jhpratt
Don't reload length in String::push

Same as in `Vec::push_mut`, we get `.len()` once at the start since it won't change in the `reserve()` call.

Saves reloading the length after the allocation: https://godbolt.org/z/W3G165Gd7
2026-04-28 05:37:22 -04:00