| Age | Commit message (Collapse) | Author | Lines |
|
Remove the ptr_unique lang item
Miri no longer uses it since https://github.com/rust-lang/miri/pull/4307.
|
|
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
|
|
Add `uX::strict_sub_signed`
rust-lang/rust#116090 missed `strict_sub_signed`, adding it here.
Part of rust-lang/rust#118260.
r? ``@m-ou-se``
|
|
Miri no longer uses it.
|
|
interpret: fix TypeId pointers being considered data pointers
Fixes https://github.com/rust-lang/miri/issues/4477
r? ````@oli-obk````
|
|
Remove deprecated `MaybeUninit` slice methods
These were left in to make migration a bit easier, although they should be removed now since they were never stable.
|
|
Stabilize `const_float_round_methods`
Closes rust-lang/rust#141555, waiting for FCP.
|
|
Allow volatile access to non-Rust memory, including address 0
This PR relaxes the `ub_check` in the `read_volatile`/`write_volatile` pointer operations to allow passing null. This is needed to support processors which hard-code peripheral registers on address 0, like the AVR chip ATtiny1626. LLVM understands this as valid and handles it correctly, as tested in my [PR to add a note about it](https://github.com/llvm/llvm-project/pull/139803/commits/6387c82255c56d3035d249eb54110695e76b8030#diff-81bbb96298c32fa901beb82ab3b97add27a410c01d577c1f8c01000ed2055826) (rustc generates the same LLVM IR as expected there when this PR is applied, and consequently the same AVR assembly).
Follow-up and implementation of the discussions in:
- https://internals.rust-lang.org/t/pre-rfc-conditionally-supported-volatile-access-to-address-0/12881/7
- https://github.com/Rahix/avr-device/pull/185;
- [#t-lang > Adding the possibility of volatile access to address 0](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/Adding.20the.20possibility.20of.20volatile.20access.20to.20address.200/with/513303502)
- https://discourse.llvm.org/t/rfc-volatile-access-to-non-dereferenceable-memory-may-be-well-defined/86303
r? ````@RalfJung````
Also fixes https://github.com/rust-lang/unsafe-code-guidelines/issues/29 (about as good as it'll get, null will likely never be a "normal" address in Rust)
|
|
|
|
intrinsics
|
|
|
|
Rollup of 10 pull requests
Successful merges:
- rust-lang/rust#141076 (fix Zip unsoundness (again))
- rust-lang/rust#142444 (adding run-make test to autodiff)
- rust-lang/rust#143704 (Be a bit more careful around exotic cycles in in the inliner)
- rust-lang/rust#144073 (Don't test panic=unwind in panic_main.rs on Fuchsia)
- rust-lang/rust#144083 (miri sleep tests: increase slack)
- rust-lang/rust#144092 (bootstrap: Detect musl hosts)
- rust-lang/rust#144098 (Do not lint private-in-public for RPITIT)
- rust-lang/rust#144103 (Rename `emit_unless` to `emit_unless_delay`)
- rust-lang/rust#144108 (Ignore tests/run-make/link-eh-frame-terminator/rmake.rs when cross-compiling)
- rust-lang/rust#144115 (fix outdated comment)
r? `@ghost`
`@rustbot` modify labels: rollup
|
|
|
|
fix Zip unsoundness (again)
Some history: The Zip TrustedRandomAccess specialization has tried to emulate the side-effects of the naive implementation for a long time, including backwards iteration. #82292 tried to fix unsoundness (#82291) in that side-effect-preservation code, but this introduced some panic-safety unsoundness (#86443), but the fix #86452 didn't fix it for nested Zip iterators (#137255).
Rather than piling yet another fix ontop of this heap of fixes this PR reduces the number of cases in which side-effects will be preserved; the necessary API guarantee change was approved in #83791 but we haven't made use of that so far.
fixes #137255
|
|
|
|
stabilize `const_slice_reverse`
cc rust-lang/rust#135120, needs FCP.
|
|
According to
https://discourse.llvm.org/t/rfc-volatile-access-to-non-dereferenceable-memory-may-be-well-defined/86303/4,
LLVM allows volatile operations on null and handles it correctly. This
should be allowed in Rust as well, because I/O memory may be hard-coded
to address 0 in some cases, like the AVR chip ATtiny1626.
A test case that ensured a failure when passing null to volatile was
removed, since it's now valid.
Due to the addition of `maybe_is_aligned` to `ub_checks`,
`maybe_is_aligned_and_not_null` was refactored to use it.
docs: revise restrictions on volatile operations
A distinction between usage on Rust memory vs. non-Rust memory was
introduced. Documentation was reworded to explain what that means, and
make explicit that:
- No trapping can occur from volatile operations;
- On Rust memory, all safety rules must be respected;
- On Rust memory, the primary difference from regular access is that
volatile always involves a memory dereference;
- On Rust memory, the only data affected by an operation is the one
pointed to in the argument(s) of the function;
- On Rust memory, provenance follows the same rules as non-volatile
access;
- On non-Rust memory, any address known to not contain Rust memory is
valid (including 0 and usize::MAX);
- On non-Rust memory, no Rust memory may be affected (it is implicit
that any other non-Rust memory may be affected, though, even if not
referenced by the pointer). This should be relevant when, for example,
reading register A causes a flag to change in register B, or writing
to A causes B to change in some way. Everything affected mustn't be
inside an allocation.
- On non-Rust memory, provenance is irrelevant and a pointer with none
can be used in a valid way.
fix: don't lint null as UB for volatile
Also remove a now-unneeded `allow` line.
fix: additional wording nits
|
|
Make slice comparisons const
This needed a fix for `derive_const`, too, as it wasn't usable in libcore anymore as trait impls need const stability attributes. I think we can't use the same system as normal trait impls while `const_trait_impl` is still unstable.
r? ```@fee1-dead```
cc rust-lang/rust#143800
|
|
constify `Option` methods
r? ```````@fee1-dead```````
tracking issue: rust-lang/rust#143956
these unblock making `PartialOrd` and `Ord` const without resorting to inlining some of these at call sites.
|
|
|
|
Also make it *only* usable on nightly
|
|
|
|
|
|
|
|
Remove deprecated `Error::description` impl from `c_str::FromBytesWithNulError`
|
|
Trim `BorrowedCursor` API
This PR removes some method from the unstable `BorrowedCursor` type. A rational for each change can be found in the message of each commit.
I don't think that an ACP is required for this, please tell me if it is not the case.
Cc rust-lang/rust#78485 rust-lang/rust#117693
|
|
Fixed a core crate compilation failure when enabling the `optimize_for_size` feature on some targets
This fixes rust-lang/rust#143804.
|
|
r=RalfJung,fee1-dead
add `const_make_global`; err for `const_allocate` ptrs if didn't call
Implements as discussed on Zulip: [#t-compiler/const-eval > const heap](https://rust-lang.zulipchat.com/#narrow/channel/146212-t-compiler.2Fconst-eval/topic/const.20heap/with/527125421)
r? ```@rust-lang/wg-const-eval```
Fixes https://github.com/rust-lang/rust/issues/129233
|
|
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```````
|
|
wrapping shift: remove first bitmask and table
```rust
#[inline(always)]
pub const fn wrapping_shl(self, rhs: u32) -> Self {
// SAFETY: the masking by the bitsize of the type ensures that we do not shift
// out of bounds
unsafe {
self.unchecked_shl(rhs & (Self::BITS - 1))
}
}
```
already does the bitmask, so it seems unnecessary here.
More context: internals.rust-lang.org/t/wrapping-shift-operator-code-doing-bitmasking-twice/23167
|
|
Co-Authored-By: Ralf Jung <post@ralfj.de>
Co-Authored-By: Oli Scherer <github333195615777966@oli-obk.de>
|
|
update `cfg_select!` documentation
tracking issue: https://github.com/rust-lang/rust/issues/115585
After rust-lang/rust#143461, and with an eye on a soon(ish) stabilization, I think the docs need some work.
The existing text read more like a motivation for the feature existing to me, so I've tried to now be a bit more descriptive. Still, suggestions are very welcome.
I also added a test for an empty `select! {}` because it's just the sort of thing that might break.
r? ``@traviscross``
|
|
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>
|
|
|
|
|
|
|
|
core: Add `BorrowedCursor::with_unfilled_buf`
Implementation of https://github.com/rust-lang/libs-team/issues/367.
This mainly adds `BorrowedCursor::with_unfilled_buf`, with enables using the unfilled part of a cursor as a `BorrowedBuf`.
Note that unlike the ACP, `BorrowedCursor::unfilled_buf` was moved to a `From` conversion. This is more consistent with other ways of creating a `BorrowedBuf` and hides a bit this conversion that requires unsafe code to be used correctly.
Cc rust-lang/rust#78485 rust-lang/rust#117693
|
|
and make internal terminology consistent
Co-authored-by: Travis Cross <tc@traviscross.com>
|
|
Updates to random number generation APIs
Updates based on discussions about random number generation.
- Add comment on `RandomSource::fill_bytes` about multiple calls, to allow
efficient implementations for random sources that generate a word at a time.
- Drop the `Random` trait in favor of `Distribution<T>`, which will let people
make calls like random(1..=6), and which allows for future expansion to
non-uniform distributions, as well as floating-point. (For now, this is only
implemented for `RangeFull`, to get the interface in place. Subsequent PRs
will implement it for other range types.)
|
|
r=oli-obk
Change "allocated object" to "allocation".
These seem like they were missed in <https://github.com/rust-lang/rust/pull/141224>
|
|
update issue number for `const_trait_impl`
r? project-const-traits
cc rust-lang/rust#67792 rust-lang/rust#143874
|
|
These seem like they were missed in <https://github.com/rust-lang/rust/pull/141224>
|
|
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>
|
|
make `cfg_select` a builtin macro
tracking issue: https://github.com/rust-lang/rust/issues/115585
This parses mostly the same as the `macro cfg_select` version, except:
1. wrapping in double brackets is no longer supported (or needed): `cfg_select {{ /* ... */ }}` is now rejected.
2. in an expression context, the rhs is no longer wrapped in a block, so that this now works:
```rust
fn main() {
println!(cfg_select! {
unix => { "foo" }
_ => { "bar" }
});
}
```
3. a single wildcard rule is now supported: `cfg_select { _ => 1 }` now works
I've also added an error if none of the rules evaluate to true, and warnings for any arms that follow the `_` wildcard rule.
cc `@traviscross` if I'm missing any feature that should/should not be included
r? `@petrochenkov` for the macro logic details
|
|
|
|
constify `From` and `Into`
tracking issue rust-lang/rust#143773
r? ``````@fee1-dead``````
I did not mark any impls elsewhere as `const`, those can happen on their own timeframe and don't need to be part of this MVP. But if there are some core ones you think should be in there I'll happily add them, just couldn't think of any
|
|
slice: Mark `rotate_left`, `rotate_right` unstably const
Tracking issue rust-lang/rust#143812
- Add the const unstable `const_slice_rotate` feature
- Mark `<[T]>::rotate_left` and `<[T]>::rotate_right` as const unstable
The internal rotate functions use [`<*mut T>::replace`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.replace) and [`ptr::swap_nonoverlapping`](https://doc.rust-lang.org/stable/core/ptr/fn.swap_nonoverlapping.html) which were const-stabilized in 1.88.
Two changes were needed in the `rotate.rs` module to make these functions const:
1. A usage of `cmp::min` was replaced with a local function implementation of [`Ord::min`](https://doc.rust-lang.org/1.88.0/src/core/cmp.rs.html#1048-1053).
2. A `for start in 1..gcd` loop was changed to a while loop with an increment variable.
This needs libs-api approval and cc-ing const-eval.
|