| Age | Commit message (Collapse) | Author | Lines |
|
|
|
|
|
|
|
|
|
inclusive `Range`s: change `end` to `last`
Tracking issue: rust-lang/rust#125687
ACP: rust-lang/libs-team#511
|
|
|
|
|
|
Constify conversion traits (part 1)
This is the first part of rust-lang/rust#144289 being split into smaller pieces. It adds/moves constness of several traits under the `const_convert` feature:
* `From`
* `Into`
* `TryFrom`
* `TryInto`
* `FromStr`
* `AsRef`
* `AsMut`
* `Borrow`
* `BorrowMut`
* `Deref`
* `DerefMut`
There are a few methods that are intrinsically tied to these traits which I've included in the feature. Particularly, those which are wrappers over `AsRef`:
* `ByteStr::new` (unstable under `bstr` feature)
* `OsStr::new`
* `Path::new`
Those which directly use `Into`:
* `Result::into_ok`
* `Result::into_err`
And those which use `Deref` and `DerefMut`:
* `Pin::as_ref`
* `Pin::as_mut`
* `Pin::as_deref_mut`
* `Option::as_deref`
* `Option::as_deref_mut`
* `Result::as_deref`
* `Result::as_deref_mut`
(note: the `Option` and `Result` methods were suggested by ``@npmccallum`` initially as rust-lang/rust#146101)
The parts which are missing from this PR are:
* Anything that involves heap-allocated types
* Making any method const than the ones listed above
* Anything that could rely on the above, *or* could rely on system-specific code for `OsStr` or `Path` (note: this mostly makes these methods useless since `str` doesn't implement `AsRef<OsStr>` yet, but it's better to track the method for now and add impls later, IMHO)
r? ``@tgross35`` (who mostly already reviewed this)
|
|
|
|
str: Stabilize `round_char_boundary` feature
Closes https://github.com/rust-lang/rust/issues/93743
FCP completed https://github.com/rust-lang/rust/issues/93743#issuecomment-3168382171
|
|
|
|
|
|
|
|
|
|
LoongArch64 LSX fast-path for `str.contains(&str)`
Benchmark results with LLVM 21 on LA664:
```
OLD:
test bench_is_contained_in ... bench: 43.63 ns/iter (+/- 0.04)
NEW:
test bench_is_contained_in ... bench: 12.81 ns/iter (+/- 0.01)
```
|
|
Benchmark results with LLVM 21 on LA664:
```
OLD:
test bench_is_contained_in ... bench: 43.63 ns/iter (+/- 0.04)
NEW:
test bench_is_contained_in ... bench: 12.81 ns/iter (+/- 0.01)
```
|
|
Remove `[T]::array_chunks(_mut)`
Since libs-api is proposing as much in https://github.com/rust-lang/rust/issues/74985#issuecomment-3024465102
Closes rust-lang/rust#74985
Closes rust-lang/rust#76354
try-job: dist-various-1
try-job: dist-various-2
|
|
|
|
Mark `floor_char_boundary`, `ceil_char_boundary` const
Simplify the implementations, reducing the number of arithmetic operations
|
|
Constify Try, From, TryFrom and relevant traits
|
|
|
|
address clippy formatting nits
- int_log10.rs: change top level doc comments to outer
- collect.rs: remove empty line after doc comment
- clippy fix: markdown indentation for indented items after line break: a markdown list item continued over multiples lines, but those following lines which are part of the same item are not indented
- clippy fix: bound in one place: when there is a bound in angle brackets and another bound on the same variable in a where clause
|
|
|
|
Constify `Index` traits
tracking issue: rust-lang/rust#143775
the `SliceIndex` trait cannot be implemented by users as it is sealed. While it would be useful for the `get` method on slices, it seems weird to have a feature gate for that that isn't also gating index syntax at the same time, so I put them under the same feature gate.
r? ```````@fee1-dead```````
|
|
r=Mark-Simulacrum
core: make `str::split_at_unchecked()` inline
This PR adds `#[inline]` to the method `str::split_at_unchecked()`. This is done for two reasons:
1. The method is tiny, e.g. on AMD-64 (<https://godbolt.org/z/ba68fdfxn>):
```asm
movq %rdi, %rax
subq %rcx, %rdx
movq %rsi, (%rdi)
addq %rcx, %rsi
movq %rcx, 8(%rdi)
movq %rsi, 16(%rdi)
movq %rdx, 24(%rdi)
retq
```
2. More importantly, inlining the method enables further automatic optimizations. E.g. if you split at index 3, then in the compiler (rustc, llvm or both) knows that this code cannot fail, and the panicking path is omitted in the generated code:
```rust
pub fn punctuation(i: &str) -> Result<(), ()> {
const THREE_CHARS: &[[u8; 3]] = &[*b"<<=", *b">>=", *b"...", *b"..="];
if let Some((head, _)) = i.split_at_checked(3)
&& THREE_CHARS.contains(&head.as_bytes().try_into().unwrap())
{
Ok(())
} else {
Err(())
}
}
```
<details>
<summary>Without PR</summary>
<https://play.rust-lang.org/?version=stable&mode=release&edition=2024&gist=0234de8158f467eebd73286f20d6e27a>
```asm
playground::punctuation:
subq $40, %rsp
movq %rsi, %rdx
movq %rdi, %rsi
movb $1, %al
cmpq $3, %rdx
ja .LBB2_2
je .LBB2_3
.LBB2_11:
addq $40, %rsp
retq
.LBB2_2:
cmpb $-64, 3(%rsi)
jl .LBB2_11
.LBB2_3:
leaq 8(%rsp), %rdi
movl $3, %ecx
callq *core::str::<impl str>::split_at_unchecked@GOTPCREL(%rip)
movq 8(%rsp), %rcx
movb $1, %al
testq %rcx, %rcx
je .LBB2_11
cmpq $3, 16(%rsp)
jne .LBB2_12
movzwl (%rcx), %edx
movzbl 2(%rcx), %ecx
shll $16, %ecx
orl %edx, %ecx
cmpl $4013115, %ecx
jg .LBB2_8
cmpl $3026478, %ecx
je .LBB2_10
cmpl $4009518, %ecx
je .LBB2_10
jmp .LBB2_11
.LBB2_8:
cmpl $4013630, %ecx
je .LBB2_10
cmpl $4013116, %ecx
jne .LBB2_11
.LBB2_10:
xorl %eax, %eax
addq $40, %rsp
retq
.LBB2_12:
leaq .Lanon.d98a7fbb86d10a97c24516e267466134.2(%rip), %rdi
leaq .Lanon.d98a7fbb86d10a97c24516e267466134.1(%rip), %rcx
leaq .Lanon.d98a7fbb86d10a97c24516e267466134.6(%rip), %r8
leaq 7(%rsp), %rdx
movl $43, %esi
callq *core::result::unwrap_failed@GOTPCREL(%rip)
```
</details>
<details>
<summary>With PR</summary>
<https://play.rust-lang.org/?version=stable&mode=release&edition=2024&gist=5d4058c79ce0f6cb1a434190427d2055>
```asm
playground::punctuation:
movb $1, %al
cmpq $3, %rsi
ja .LBB0_2
je .LBB0_3
.LBB0_9:
retq
.LBB0_2:
cmpb $-64, 3(%rdi)
jl .LBB0_9
.LBB0_3:
movzwl (%rdi), %eax
movzbl 2(%rdi), %ecx
shll $16, %ecx
orl %eax, %ecx
movb $1, %al
cmpl $4013115, %ecx
jg .LBB0_6
cmpl $3026478, %ecx
je .LBB0_8
cmpl $4009518, %ecx
je .LBB0_8
jmp .LBB0_9
.LBB0_6:
cmpl $4013630, %ecx
je .LBB0_8
cmpl $4013116, %ecx
jne .LBB0_9
.LBB0_8:
xorl %eax, %eax
retq
```
</details>
|
|
|
|
|
|
|
|
This PR adds `#[inline]` to the method `str::split_at_unchecked()`.
This is done for two reasons:
1. The method is tiny, e.g. on AMD-64 (<https://godbolt.org/z/ba68fdfxn>):
```asm
movq %rdi, %rax
subq %rcx, %rdx
movq %rsi, (%rdi)
addq %rcx, %rsi
movq %rcx, 8(%rdi)
movq %rsi, 16(%rdi)
movq %rdx, 24(%rdi)
retq
```
2. More importantly, inlining the method enables further automatic
optimizations. E.g. if you split at index 3, then in the compiler
(rustc, llvm or both) knows that this code cannot fail, and the
panicking path is omitted in the generated code:
```rust
pub fn punctuation(i: &str) -> Result<(), ()> {
const THREE_CHARS: &[[u8; 3]] = &[*b"<<=", *b">>=", *b"...", *b"..="];
if let Some((head, _)) = i.split_at_checked(3)
&& THREE_CHARS.contains(&head.as_bytes().try_into().unwrap())
{
Ok(())
} else {
Err(())
}
}
```
<details>
<summary>Without PR</summary>
<https://play.rust-lang.org/?version=stable&mode=release&edition=2024&gist=0234de8158f467eebd73286f20d6e27a>
```asm
playground::punctuation:
subq $40, %rsp
movq %rsi, %rdx
movq %rdi, %rsi
movb $1, %al
cmpq $3, %rdx
ja .LBB2_2
je .LBB2_3
.LBB2_11:
addq $40, %rsp
retq
.LBB2_2:
cmpb $-64, 3(%rsi)
jl .LBB2_11
.LBB2_3:
leaq 8(%rsp), %rdi
movl $3, %ecx
callq *core::str::<impl str>::split_at_unchecked@GOTPCREL(%rip)
movq 8(%rsp), %rcx
movb $1, %al
testq %rcx, %rcx
je .LBB2_11
cmpq $3, 16(%rsp)
jne .LBB2_12
movzwl (%rcx), %edx
movzbl 2(%rcx), %ecx
shll $16, %ecx
orl %edx, %ecx
cmpl $4013115, %ecx
jg .LBB2_8
cmpl $3026478, %ecx
je .LBB2_10
cmpl $4009518, %ecx
je .LBB2_10
jmp .LBB2_11
.LBB2_8:
cmpl $4013630, %ecx
je .LBB2_10
cmpl $4013116, %ecx
jne .LBB2_11
.LBB2_10:
xorl %eax, %eax
addq $40, %rsp
retq
.LBB2_12:
leaq .Lanon.d98a7fbb86d10a97c24516e267466134.2(%rip), %rdi
leaq .Lanon.d98a7fbb86d10a97c24516e267466134.1(%rip), %rcx
leaq .Lanon.d98a7fbb86d10a97c24516e267466134.6(%rip), %r8
leaq 7(%rsp), %rdx
movl $43, %esi
callq *core::result::unwrap_failed@GOTPCREL(%rip)
```
</details>
<details>
<summary>With PR</summary>
<https://play.rust-lang.org/?version=stable&mode=release&edition=2024&gist=5d4058c79ce0f6cb1a434190427d2055>
```asm
playground::punctuation:
movb $1, %al
cmpq $3, %rsi
ja .LBB0_2
je .LBB0_3
.LBB0_9:
retq
.LBB0_2:
cmpb $-64, 3(%rdi)
jl .LBB0_9
.LBB0_3:
movzwl (%rdi), %eax
movzbl 2(%rdi), %ecx
shll $16, %ecx
orl %eax, %ecx
movb $1, %al
cmpl $4013115, %ecx
jg .LBB0_6
cmpl $3026478, %ecx
je .LBB0_8
cmpl $4009518, %ecx
je .LBB0_8
jmp .LBB0_9
.LBB0_6:
cmpl $4013630, %ecx
je .LBB0_8
cmpl $4013116, %ecx
jne .LBB0_9
.LBB0_8:
xorl %eax, %eax
retq
```
</details>
|
|
|
|
|
|
Full list of `impl const Default` types:
- ()
- bool
- char
- Cell
- std::ascii::Char
- usize
- u8
- u16
- u32
- u64
- u128
- i8
- i16
- i32
- i64
- i128
- f16
- f32
- f64
- f128
- std::marker::PhantomData<T>
- Option<T>
- std::iter::Empty<T>
- std::ptr::Alignment
- &[T]
- &mut [T]
- &str
- &mut str
- String
- Vec<T>
|
|
There is no reason to go through the complicated branch as it would
always return `self.len()` in this case. Also helps debug code somewhat
and I guess might make optimizations easier (although I haven't really a
sample to demonstrate this.)
ref. #93743
Suggested by @chrisduerr
|
|
|
|
|
|
|
|
Add note about `str::split` handling of no matches.
Adds small note and example to the test for a non matching pattern
resolves rust-lang/rust#142734
|
|
|
|
Implements `trim_prefix` and `trim_suffix` methods for both `slice` and
`str` types which remove at most one occurrence of a prefix/suffix while
always returning a string/slice (rather than Option), enabling easy
method chaining.
|
|
|
|
- Drop the phrasing "usually a mistake".
- Mention that `Display` may not be lossless.
- Drop a misplaced parenthetical about round-tripping that didn't fit
the paragraph it was in.
|
|
|
|
In particular:
- `Display` is not necessarily lossless
- The output of `Display` might not be parseable by `FromStr`, and might
not produce the same value if it is.
- Calling `.parse()` on the output of `Display` is usually a mistake
unless a type's documented output and input formats match.
- The input formats accepted by `FromStr` depend on the type.
|
|
std: note that `std::str::from_utf8*` functions are aliases to `<str>::from_utf8*` methods
Closes #141079
r? libs
|
|
`std::<str>::from_utf8*` methods
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
|
|
This reverts commit 245bf503e2a948ac98170516d11df632e85a948b.
|
|
Add some track_caller info to precondition panics
Currently, when you encounter a precondition check, you'll always get the caller location of the implementation of the precondition checks. But with this PR, you'll be told the location of the invalid call. Which is useful.
I thought of this while looking at https://github.com/rust-lang/rust/pull/129642#issuecomment-2311703898.
The changes to `tests/ui/const*` happen because the const-eval interpreter skips `#[track_caller]` frames in its backtraces.
The perf implications of this are:
* Increased debug binary sizes. The caller_location implementation requires that the additional data we want to display here be stored in const allocations, which are deduplicated but not across crates. There is no impact on optimized build sizes. The panic path and the caller location data get optimized out.
* The compile time hit to opt-incr-patched bitmaps happens because the patch changes the line number of some function calls with precondition checks, causing us to go from 0 dirty CGUs to 1 dirty CGU.
* The other compile time hits are marginal but real, and due to doing a handful of new queries. Adding more useful data isn't completely free.
|
|
speed up charsearcher for ascii chars
attempt at fixing rust-lang/rust#82471
this implementation should be valid because ascii characters are always one byte and there are no continuation bytes that overlap with ascii characters
im not completely sure that this is _always_ an improvement but it seems to be an improvement for this case and i dont think it can significantly regress any cases
|
|
Specify that split_ascii_whitespace uses the same definition as is_ascii_whitespace
|
|
|