about summary refs log tree commit diff
path: root/library/alloc
AgeCommit message (Collapse)AuthorLines
2023-08-22Auto merge of #113365 - dima74:diralik/add-deprecated-suggestions, ↵bors-1/+2
r=workingjubilee Add `suggestion` for some `#[deprecated]` items Consider code: ```rust fn main() { let _ = ["a", "b"].connect(" "); } ``` Currently it shows deprecated warning: ```rust warning: use of deprecated method `std::slice::<impl [T]>::connect`: renamed to join --> src/main.rs:2:24 | 2 | let _ = ["a", "b"].connect(" "); | ^^^^^^^ | = note: `#[warn(deprecated)]` on by default ``` This PR adds `suggestion` for `connect` and some other deprecated items, so the warning will be changed to this: ```rust warning: use of deprecated method `std::slice::<impl [T]>::connect`: renamed to join --> src/main.rs:2:24 | 2 | let _ = ["a", "b"].connect(" "); | ^^^^^^^ | = note: `#[warn(deprecated)]` on by default help: replace the use of the deprecated method | 2 | let _ = ["a", "b"].join(" "); | ^^^^ ```
2023-08-21Add `suggestion` for some `#[deprecated]` itemsDmitry Murzin-1/+2
2023-08-19Correct and expand documentation of `handle_alloc_error` and ↵Kevin Reid-6/+19
`set_alloc_error_hook`. Add the following facts: * `handle_alloc_error` may panic instead of aborting. * What happens if a hook returns rather than diverging. * A hook may panic. (This was already demonstrated in an example, but not stated in prose.) * A hook must be sound to call — it cannot assume that it is only called by the runtime, since its function pointer can be retrieved by safe code.
2023-08-18resolve conflictsKyle Lin-0/+1
2023-08-18relax redundancy constraintKyle Lin-4/+2
2023-08-17Auto merge of #114799 - RalfJung:less-transmute, r=m-ou-sebors-2/+2
avoid transmuting Box when we can just cast raw pointers instead Always better to avoid a transmute, in particular when the layout assumptions it is making are not clearly documented. :)
2023-08-16Update library/alloc/src/vec/mod.rsManish Goregaokar-1/+1
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-08-16Update library/alloc/src/vec/mod.rsManish Goregaokar-1/+2
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-08-16Rollup merge of #114867 - ttsugriy:ttsugriy-patch-1, r=scottmcmMatthias Krüger-1/+1
[nit] Fix a comment typo.
2023-08-16Rollup merge of #114861 - RalfJung:no-effect, r=wesleywiserMatthias Krüger-1/+1
fix typo: affect -> effect I just realized I made a silly typo when writing that comment...
2023-08-15other elementsManish Goregaokar-3/+3
2023-08-15[nit] Fix a comment typo.Taras Tsugrii-1/+1
2023-08-15fix typo: affect -> effectRalf Jung-1/+1
2023-08-15Update library/alloc/src/vec/mod.rsManish Goregaokar-1/+1
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-08-15Update library/alloc/src/vec/mod.rsManish Goregaokar-1/+1
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-08-15Auto merge of #112387 - clarfonthey:non-panicking-ceil-char-boundary, r=m-ou-sebors-5/+2
Don't panic in ceil_char_boundary Implementing the alternative mentioned in this comment: https://github.com/rust-lang/rust/issues/93743#issuecomment-1579935853 Since `floor_char_boundary` will always work (rounding down to the length of the string is possible), it feels best for `ceil_char_boundary` to not panic either. However, the semantics of "rounding up" past the length of the string aren't very great, which is why the method originally panicked in these cases. Taking into account how people are using this method, it feels best to simply return the end of the string in these cases, so that the result is still a valid char boundary.
2023-08-14avoid transmuting Box when we can just cast raw pointers insteadRalf Jung-2/+2
2023-08-13core/any: remove Provider traitwayne warren-2/+1
* remove `impl Provider for Error` * rename `Demand` to `Request` * update docstrings to focus on the conceptual API provided by `Request` * move `core::any::{request_ref, request_value}` functions into `core::error` * move `core::any::tag`, `core::any::Request`, an `core::any::TaggedOption` into `core::error` * replace `provide_any` feature name w/ `error_generic_member_access` * move `core::error::request_{ref,value} tests into core::tests::error module * update unit and doc tests
2023-08-12aliasing guaranteeManish Goregaokar-25/+40
2023-08-10Rollup merge of #114402 - tifv:tifv-fix-rc-doc, r=cuviperMichael Goulet-3/+3
Fix documentation of impl From<Vec<T>> for Rc<[T]> The example in the documentation of `impl From<Vec<T>> for <Rc<[T]>` is irrelevant (likely was copied from `impl From<Box<T>> for <Rc<T>`). I suggest taking corresponding example from the documentation of `Arc` and replacing `Arc` with `Rc`.
2023-08-10Rollup merge of #114257 - rytheo:linked-list-avoid-unique, r=cuviperMichael Goulet-11/+13
Avoid using `ptr::Unique` in `LinkedList` code Addresses a [comment](https://github.com/rust-lang/rust/pull/103093#discussion_r1268506747) by `@RalfJung` about avoiding use of `core::ptr::Unique` in the standard library.
2023-08-07Rollup merge of #114365 - tshepang:patch-6, r=Mark-SimulacrumMatthias Krüger-6/+0
str.rs: remove "Basic usage" text Only one example is given
2023-08-07Rollup merge of #114362 - tshepang:patch-1, r=Mark-SimulacrumMatthias Krüger-72/+1
string.rs: remove "Basic usage" text Only a single example is given
2023-08-06Add #[rustc_never_returns_null_ptr] to std functionsest31-0/+6
Add the attribute to standard library functions that are guaranteed to never return null pointers, as their originating data wouldn't allow it.
2023-08-03Add `internal_features` lintNilstrieb-0/+1
It lints against features that are inteded to be internal to the compiler and standard library. Implements MCP #596. We allow `internal_features` in the standard library and compiler as those use many features and this _is_ the standard library from the "internal to the compiler and standard library" after all. Marking some features as internal wasn't exactly the most scientific approach, I just marked some mostly obvious features. While there is a categorization in the macro, it's not very well upheld (should probably be fixed in another PR). We always pass `-Ainternal_features` in the testsuite About 400 UI tests and several other tests use internal features. Instead of throwing the attribute on each one, just always allow them. There's nothing wrong with testing internal features^^
2023-08-03Fix documentation of Rc as From<Vec<T>>July Tikhonov-3/+3
2023-08-02str.rs: remove "Basic usage" textTshepang Mbambo-6/+0
Only one example is given
2023-08-02string.rs: remove "Basic usage" textTshepang Mbambo-72/+1
Only a single example is given
2023-07-31Rollup merge of #114111 - allaboutevemirolive:add-test-case-string, ↵Matthias Krüger-2/+46
r=Mark-Simulacrum Improve test case for experimental API remove_matches ## Add Test Cases for `remove_matches` Function ### Motivation After reading the discussion in [this GitHub thread](https://github.com/rust-lang/rust/pull/71780), I'm trying to redesign the current API to use less memory when working with `String` and to make it simpler. I've discovered that some test cases are very helpful in ensuring that the new API behaves as intended. I'm still in the process of redesigning the current API, and these test cases have proven to be very useful. ### Testing The current test has been tested with the command `./x test --stage 0 library/alloc`. ### Overview This pull request adds several new test cases for the `remove_matches` function to make sure it works correctly in different situations. The `remove_matches` function is used to get rid of all instances of a specific pattern from a given text. These test cases thoroughly check how the function behaves in various scenarios. ### Test Cases 1. **Single Pattern Occurrence** (`test_single_pattern_occurrence`): - Description: Tests the removal of a single pattern occurrence from the text. - Input: Text: "abc", Pattern: 'b' - Expected Output: "ac" 2. **Repeat Test Single Pattern Occurrence** (`repeat_test_single_pattern_occurrence`): - Description: Repeats the previous test case to ensure consecutive removal of the same pattern. - Input: Text: "ac", Pattern: 'b' - Expected Output: "ac" 3. **Single Character Pattern** (`test_single_character_pattern`): - Description: Tests the removal of a single character pattern. - Input: Text: "abcb", Pattern: 'b' - Expected Output: "ac" 4. **Pattern with Special Characters** (`test_pattern_with_special_characters`): - Description: Tests the removal of a pattern containing special characters. - Input: Text: "ศไทย中华Việt Nam; foobarศ", Pattern: 'ศ' - Expected Output: "ไทย中华Việt Nam; foobar" 5. **Pattern Empty Text and Pattern** (`test_pattern_empty_text_and_pattern`): - Description: Tests the removal of an empty pattern from an empty text. - Input: Text: "", Pattern: "" - Expected Output: "" 6. **Pattern Empty Text** (`test_pattern_empty_text`): - Description: Tests the removal of a pattern from an empty text. - Input: Text: "", Pattern: "something" - Expected Output: "" 7. **Empty Pattern** (`test_empty_pattern`): - Description: Tests the behavior of removing an empty pattern from the text. - Input: Text: "Testing with empty pattern.", Pattern: "" - Expected Output: "Testing with empty pattern." 8. **Multiple Consecutive Patterns 1** (`test_multiple_consecutive_patterns_1`): - Description: Tests the removal of multiple consecutive occurrences of a pattern. - Input: Text: "aaaaa", Pattern: 'a' - Expected Output: "" 9. **Multiple Consecutive Patterns 2** (`test_multiple_consecutive_patterns_2`): - Description: Tests the removal of a longer pattern that occurs consecutively. - Input: Text: "Hello **world****today!**", Pattern: "**" - Expected Output: "Hello worldtoday!" 10. **Case Insensitive Pattern** (`test_case_insensitive_pattern`): - Description: Tests the removal of a case-insensitive pattern from the text. - Input: Text: "CASE ** SeNsItIvE ** PaTtErN.", Pattern: "sEnSiTiVe" - Expected Output: "CASE ** SeNsItIvE ** PaTtErN."
2023-07-30Rollup merge of #95965 - CAD97:const-weak-new, r=workingjubileeJubilee-2/+2
Stabilize const-weak-new This is a fairly uncontroversial library stabilization, so I'm going ahead and proposing it to ride the trains to stable. This stabilizes the following APIs, which are defined to be non-allocating constructors. ```rust // alloc::rc impl<T> Weak<T> { pub const fn new() -> Weak<T>; } // alloc::sync impl<T> Weak<T> { pub const fn new() -> Weak<T>; } ``` Closes #95091 ``@rustbot`` modify labels: +needs-fcp
2023-07-30Stabilize const-weak-newCAD97-2/+2
Bump its stabilization version several times along the way to accommodate changes in release processes. Co-authored-by: Mara Bos <m-ou.se@m-ou.se> Co-authored-by: Trevor Gross <t.gross35@gmail.com>
2023-07-30Avoid using ptr::Unique in LinkedList codeRyan Lowe-11/+13
2023-07-30Rollup merge of #114223 - ryanoneill:vec-indexing-doc-language, r=workingjubileeMatthias Krüger-1/+1
Documentation: Fix Stilted Language in Vec->Indexing Problem Language in the Vec->Indexing documentation sounds stilted due to incorrect word ordering: "... type allows to access values by index." Solution Reorder words in the Vec->Indexing documentation to flow better: "... type allows access to values by index." The phrase "allows access to" also matches other existing documentation.
2023-07-30Auto merge of #114236 - fee1-dead-contrib:rollup-m92j7q1, r=fee1-deadbors-0/+8
Rollup of 3 pull requests Successful merges: - #112151 (Clarify behavior of inclusive bounds in BTreeMap::{lower,upper}_bound) - #113512 (Updated lines doc to include trailing carriage return note) - #114203 (Effects: don't print `host` param in diagnostics) r? `@ghost` `@rustbot` modify labels: rollup
2023-07-30Rollup merge of #112151 - chloekek:patch-1, r=workingjubileefee1-dead-0/+8
Clarify behavior of inclusive bounds in BTreeMap::{lower,upper}_bound It wasn’t quite clear to me how these methods would interpret inclusive bounds so I added examples for those.
2023-07-30Auto merge of #112280 - zica87:master, r=workingjubileebors-13/+0
Remove redundant example of `BTreeSet::iter` The usage and that `Values returned by the iterator are returned in ascending order` are already demonstrated by the other example and the description, so I removed the useless one.
2023-07-29Documentation: Fix Stilted Language in Vec->IndexingRyan O'Neill-1/+1
Problem Language in the Vec->Indexing documentation sounds stilted due to incorrect word ordering: "... type allows to access values by index." Solution Reorder words in the Vec->Indexing documentation to flow better: "... type allows access to values by index." The phrase "allows access to" also matches other existing documentation.
2023-07-28btree/map.rs: remove "Basic usage" textTshepang Mbambo-54/+0
Not useful, for there is just a single example
2023-07-28add LinkedList::{retain,retain_mut}TennyZhuang-0/+93
Signed-off-by: TennyZhuang <zty0826@gmail.com>
2023-07-26Improve test case for experimental API remove_matches in ↵allaboutevemirolive-2/+46
library/alloc/tests/string.rs
2023-07-25Add note that Vec::as_mut_ptr() does not materialize a reference to the ↵Manish Goregaokar-0/+35
internal buffer
2023-07-25Auto merge of #114020 - steffahn:hide-specialized-ToString-impls, r=thomccbors-0/+9
Hide `ToString` implementations that specialize the default one The status quo is highly confusing, since the overlap is not apparent, and specialization is not a feature of Rust. This change addresses #87545; I'm not certain if it closes/fixes it entirely, since that issue might also be tracking the question of a *general* solution for hiding the documentation for specializing impls automatically. Before ![Screenshot_20230724_234210](https://github.com/rust-lang/rust/assets/3986214/54bbe659-1790-4e95-a5d8-5426e710ceb8) After ![Screenshot_20230724_234255](https://github.com/rust-lang/rust/assets/3986214/ee645d6e-c1c0-40c0-a0d3-a5c5f3dae65e)
2023-07-24Implement `From<[T; N]>` for `Rc<[T]>` and `Arc<[T]>`Nikolai Vazquez-0/+42
2023-07-24remove additional [allow(unused_unsafe)]James Dietz-1/+0
2023-07-24Hide `ToString` implementations that specialize the default onesFrank Steffahn-0/+9
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-22Auto merge of #113954 - matthiaskrgr:rollup-e2r9suz, r=matthiaskrgrbors-8/+30
Rollup of 6 pull requests Successful merges: - #112490 (Remove `#[cfg(all())]` workarounds from `c_char`) - #113252 (Update the tracking issue for `const_cstr_from_ptr`) - #113442 (Allow limited access to `OsString` bytes) - #113876 (fix docs & example for `std::os::unix::prelude::FileExt::write_at`) - #113898 (Fix size_hint for EncodeUtf16) - #113934 (Multibyte character removal in String::pop and String::remove doctests) r? `@ghost` `@rustbot` modify labels: rollup
2023-07-22Rollup merge of #113934 - ajtribick:string-pop-remove-multibyte, r=thomccMatthias Krüger-8/+8
Multibyte character removal in String::pop and String::remove doctests I think it would be useful to have the doctests for the `String::pop()` and `String::remove()` methods demonstrate that they work on multibyte UTF-8 sequences.
2023-07-22Rollup merge of #113898 - ajtribick:encode_utf16_size_hint, r=cuviperMatthias Krüger-0/+22
Fix size_hint for EncodeUtf16 More realistic upper and lower bounds, and handle the case where the iterator is located within a surrogate pair. Resolves #113897
2023-07-22Auto merge of #113224 - zachs18:vec_extend_remove_allocator_lifetime, r=cuviperbors-3/+3
Remove lifetime bound for A for `impl Extend<&'a T> for Vec<T, A>`. The lifetime of the references being copied from is unrelated to the allocator. Compare with [`impl<'a, T: 'a + Copy, A: Allocator> Extend<&'a T> for VecDeque<T, A>`](https://doc.rust-lang.org/alloc/collections/vec_deque/struct.VecDeque.html#impl-Extend%3C%26'a+T%3E-for-VecDeque%3CT,+A%3E) which does not have the `A: 'a` bound already. Since `Allocator` is unstable, the only possible `A` on stable is `Global`, and `Global: 'static`, so this change is not (should not be) observable on stable (or without `#![feature(allocator_api)]`). [This is observable on nightly](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=8c4aa166c6116a90593d2934d30cfeb3).
2023-07-21Demonstrate multibyte character removal in String::pop and String::remove ↵Andrew Tribick-8/+8
doctests