Commit Graph

2216 Commits

Author SHA1 Message Date
Michael Goulet
9546d7140e
Rollup merge of #114402 - tifv:tifv-fix-rc-doc, r=cuviper
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-10 21:17:37 -07:00
Michael Goulet
3791f6dded
Rollup merge of #114257 - rytheo:linked-list-avoid-unique, r=cuviper
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-10 21:17:36 -07:00
Matthias Krüger
f5df519fe7
Rollup merge of #114365 - tshepang:patch-6, r=Mark-Simulacrum
str.rs: remove "Basic usage" text

Only one example is given
2023-08-07 05:29:12 +02:00
Matthias Krüger
59d2a4b1e5
Rollup merge of #114362 - tshepang:patch-1, r=Mark-Simulacrum
string.rs: remove "Basic usage" text

Only a single example is given
2023-08-07 05:29:11 +02:00
Nilstrieb
5830ca216d Add internal_features lint
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-03 14:50:50 +02:00
July Tikhonov
f1fc871ce6
Fix documentation of Rc as From<Vec<T>> 2023-08-03 10:44:23 +03:00
Tshepang Mbambo
60e43bcf57
str.rs: remove "Basic usage" text
Only one example is given
2023-08-02 12:14:43 +02:00
Tshepang Mbambo
e47cd2f250
string.rs: remove "Basic usage" text
Only a single example is given
2023-08-02 11:17:57 +02:00
Matthias Krüger
e981db05b5
Rollup merge of #114111 - allaboutevemirolive:add-test-case-string, 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-31 22:49:51 +02:00
Jubilee
e5a6e5c90d
Rollup merge of #95965 - CAD97:const-weak-new, r=workingjubilee
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-30 17:50:46 -07:00
CAD97
ee29d2fd0a Stabilize const-weak-new
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-30 17:07:59 -07:00
Ryan Lowe
80277dd8f2 Avoid using ptr::Unique in LinkedList code 2023-07-30 11:21:24 -04:00
Matthias Krüger
de6caffe3a
Rollup merge of #114223 - ryanoneill:vec-indexing-doc-language, r=workingjubilee
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-30 14:25:10 +02:00
bors
4c9ac1e93b Auto merge of #114236 - fee1-dead-contrib:rollup-m92j7q1, r=fee1-dead
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-30 07:57:13 +00:00
fee1-dead
3143030cda
Rollup merge of #112151 - chloekek:patch-1, r=workingjubilee
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-30 07:13:01 +00:00
bors
2e0136a131 Auto merge of #112280 - zica87:master, r=workingjubilee
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-30 06:12:03 +00:00
Ryan O'Neill
9a01a23b9c 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-29 13:20:45 -07:00
Tshepang Mbambo
85779214c8
btree/map.rs: remove "Basic usage" text
Not useful, for there is just a single example
2023-07-28 14:24:56 +02:00
allaboutevemirolive
adb36cb866 Improve test case for experimental API remove_matches in library/alloc/tests/string.rs 2023-07-26 17:54:48 -04:00
bors
c026d6a400 Auto merge of #114020 - steffahn:hide-specialized-ToString-impls, r=thomcc
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-25 07:31:15 +00:00
James Dietz
db4a153440 remove additional [allow(unused_unsafe)] 2023-07-24 17:56:38 -04: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
bors
42f5419dd2 Auto merge of #113954 - matthiaskrgr:rollup-e2r9suz, r=matthiaskrgr
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-22 11:30:18 +00:00
Matthias Krüger
37cd63431c
Rollup merge of #113934 - ajtribick:string-pop-remove-multibyte, r=thomcc
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-22 11:48:55 +02:00
Matthias Krüger
65b5cba0dd
Rollup merge of #113898 - ajtribick:encode_utf16_size_hint, r=cuviper
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-22 11:48:54 +02:00
bors
dcb810414e Auto merge of #113224 - zachs18:vec_extend_remove_allocator_lifetime, r=cuviper
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-22 09:44:50 +00:00
Andrew Tribick
2c145982a5 Demonstrate multibyte character removal in String::pop and String::remove doctests 2023-07-21 23:40:55 +02:00
Andrew Tribick
e6fa5c18b5 Fix size_hint for EncodeUtf16 2023-07-20 21:52:33 +02:00
Mike Hommey
b1398cac9d Make {Rc,Arc}::allocator associated functions 2023-07-18 09:58:27 +09:00
bors
da6b55cc5e Auto merge of #89132 - Cyborus04:rc_allocator_support, r=Amanieu
Add support for allocators in `Rc` & `Arc`

Adds the ability for `std::rc:Rc`, `std::rc::Weak`, `std::sync::Arc`, and `std::sync::Weak` to live in custom allocators
2023-07-17 21:51:46 +00:00
Matthias Krüger
a42b04c408
Rollup merge of #113662 - pedroclobo:vec-deque-rotate, r=thomcc
Rename VecDeque's `rotate_left` and `rotate_right` parameters

This pull request introduces a modification to the `VecDeque` collection, specifically the `rotate_left` and `rotate_right` functions, by renaming the parameter associated with these functions.

The rationale behind this change is to provide clearer and more consistent naming for the parameter that specifies the number of places to rotate the double-ended queue. By using `n` as the parameter name in both functions, it becomes easier to understand and remember the purpose of the parameter.
2023-07-14 19:33:26 +02:00
bors
cca3373706 Auto merge of #113113 - Amanieu:box-vec-zst, r=Mark-Simulacrum
Eliminate ZST allocations in `Box` and `Vec`

This PR fixes 2 issues with `Box` and `RawVec` related to ZST allocations. Specifically, the `Allocator` trait requires that:
- If you allocate a zero-sized layout then you must later deallocate it, otherwise the allocator may leak memory.
- You cannot pass a ZST pointer to the allocator that you haven't previously allocated.

These restrictions exist because an allocator implementation is allowed to allocate non-zero amounts of memory for a zero-sized allocation. For example, `malloc` in libc does this.

Currently, ZSTs are handled differently in `Box` and `Vec`:
- `Vec` never allocates when `T` is a ZST or if the vector capacity is 0.
- `Box` just blindly passes everything on to the allocator, including ZSTs.

This causes problems due to the free conversions between `Box<[T]>` and `Vec<T>`, specifically that ZST allocations could get leaked or a dangling pointer could be passed to `deallocate`.

This PR fixes this by changing `Box` to not allocate for zero-sized values and slices. It also fixes a bug in `RawVec::shrink` where shrinking to a size of zero did not actually free the backing memory.
2023-07-14 01:59:08 +00:00
Pedro Lobo
30a029e51b
Fix VecDeque's rotate_left and rotate_right panic tests 2023-07-13 18:39:09 +01:00
Pedro Lobo
c0a105be7c
Rename VecDeque's rotate_left and rotate_right parameters 2023-07-13 18:10:52 +01:00
Amanieu d'Antras
d24be14276 Eliminate ZST allocations in Box and Vec 2023-07-13 15:00:53 +01:00
Mark Rousskov
67b0cfc761 Flip cfg's for bootstrap bump 2023-07-12 21:38:55 -04:00
Mark Rousskov
0d93d787ba Replace version placeholder to 1.72 2023-07-12 21:24:05 -04:00
Michael Goulet
7913d76cb9
Rollup merge of #113318 - tgross35:113283-allocator-trait-eq, r=m-ou-se
Revert "alloc: Allow comparing Boxs over different allocators", add regression test

Temporary fix for #113283

Adds a test to fix the regression introduced in 001b081cc1 and revert that commit. The test fails without the revert.
2023-07-06 20:11:40 -07:00
Trevor Gross
a635bf7a3b Revert "alloc: Allow comparing Boxs over different allocators"
This reverts commit 001b081cc1.

This change was done as the above commit introduces a regression in type
inference. Regression test located at
`tests/ui/type-inference/issue-113283-alllocator-trait-eq.rs`
2023-07-04 05:02:00 -04:00
Ralf Jung
e1338cc254 enable test_join test in Miri 2023-07-03 14:05:55 +02:00
Matthias Krüger
023f72ad5b
Rollup merge of #113253 - nurmukhametdaniyar:rc_from_cstr_doc_fix, r=Nilstrieb
Fixed documentation of from<CString> for Rc<CStr>: Arc -> Rc

Fix #113131
2023-07-02 23:30:46 +02:00
Daniyar Nurmukhamet
99599db8f0 fixed documentation of from<CString> for Rc<CStr>: Arc -> Rc 2023-07-02 10:07:52 +06:00
Zachary S
0699345e7a Remove lifetime bound for A for impl Extend<&'a T> for Vec<T, A>. 2023-07-01 02:12:45 -05:00
Cyborus04
215cf36d64
Add support for allocators in Rc and Arc 2023-06-30 11:40:19 -04:00
Cyborus04
a52f8f688b
Add support for allocators in Rc and Arc 2023-06-30 11:33:16 -04:00
Li Zhanhui
9a67df290c
Fix document examples of Vec::from_raw_parts and Vec::from_raw_parts_in
Signed-off-by: Li Zhanhui <lizhanhui@gmail.com>
2023-06-29 04:21:00 +00:00
Matthias Krüger
448d2a8417
Rollup merge of #112628 - gootorov:box_alloc_partialeq, r=joshtriplett
Allow comparing `Box`es with different allocators

Currently, comparing `Box`es over different allocators is not allowed:
```Rust
error[E0308]: mismatched types
  --> library/alloc/tests/boxed.rs:22:20
   |
22 |     assert_eq!(b1, b2);
   |                    ^^ expected `Box<{integer}, ConstAllocator>`, found `Box<{integer}, AnotherAllocator>`
   |
   = note: expected struct `Box<{integer}, ConstAllocator>`
              found struct `Box<{integer}, AnotherAllocator>`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `alloc` (test "collectionstests") due to previous error
```
This PR lifts this limitation
2023-06-27 22:10:13 +02:00
Takayuki Maeda
c6a4d44977
Rollup merge of #112677 - the8472:remove-unusued-field, r=JohnTitor
remove unused field

Followup to #104455. The field is no longer needed since ExtractIf (previously DrainFilter) doesn't keep draining in its drop impl.
2023-06-26 23:16:16 +09:00
Amanieu d'Antras
4a9f292e50 Expose compiler-builtins-weak-intrinsics feature for -Zbuild-std
This was added in rust-lang/compiler-builtins#526 to force all
compiler-builtins intrinsics to use weak linkage.
2023-06-23 11:15:34 +01:00
bors
97bf23d26b Auto merge of #112877 - Nilstrieb:rollup-5g5hegl, r=Nilstrieb
Rollup of 6 pull requests

Successful merges:

 - #112632 (Implement PartialOrd for `Vec`s over different allocators)
 - #112759 (Make closure_saved_names_of_captured_variables a query. )
 - #112772 (Add a fully fledged `Clause` type, rename old `Clause` to `ClauseKind`)
 - #112790 (Syntactically accept `become` expressions (explicit tail calls experiment))
 - #112830 (More codegen cleanups)
 - #112844 (Add retag in MIR transform: `Adt` for `Unique` may contain a reference)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-21 08:00:23 +00:00