9803 Commits

Author SHA1 Message Date
Matthias Krüger
b46db5c6b7
Rollup merge of #140153 - thaliaarchi:encode-wide-debug, r=ChrisDenton
Implement `Debug` for `EncodeWide`

Since `std::os::windows::ffi::EncodeWide` was reexported from `std::sys_common::wtf8::EncodeWide`, which has `#![allow(missing_debug_implementations)]` in the parent module, it did not implement `Debug`. When it was moved to `core`, a placeholder impl was added; fill it in.

This becomes insta-stable.

r? libs-api
2025-10-18 08:08:35 +02:00
Travis Cross
73f5fe78d4 Revise Result/Option guarantee docs
The notation used here (e.g. "transmute `t: T` to `Option<T>`") felt
maybe a bit heavy, in the context of the library documentation, so
let's elaborate this a bit.

Also, in the `Option` docs, we talk about this being true for "the
following types `T`", but it felt this caveat might get a bit lost in
the next sentence that talks about the valid transmutations, so let's
reiterate the caveat.

While we're touching the line, we can improve:

> The only difference is the implied semantics:

This sentence was a bit awkward due to the mismatched plurality and
not identifying the difference being spoken to.  We'll reword this to
make it more clear.

We'll wrap to 80, since the existing text and most of the doc comments
in these files are wrapped this way.
2025-10-18 00:59:17 +00:00
Ralf Jung
058f08dd78 have Result docs match ABI docs 2025-10-17 23:18:14 +00:00
Ralf Jung
781432e355 clarify 'no fields' 2025-10-17 23:18:14 +00:00
Ralf Jung
29a19f84c2 Result/Option layout guarantee clarifications 2025-10-17 23:18:14 +00:00
ltdk
97b7170eef const Cell methods 2025-10-16 16:09:31 -04:00
nxsaken
e834a2e55f Remove whitespace 2025-10-16 22:41:45 +04:00
nxsaken
298d825cbb Return Option from exact_div and inherit overflow checks 2025-10-16 22:03:50 +04:00
Matthias Krüger
f337e28bd9
Rollup merge of #147773 - timvisee:docs-empty-is-ascii, r=Noratrieb
`is_ascii` on an empty string or slice returns true

Update the description of the [`is_ascii`](https://doc.rust-lang.org/std/primitive.str.html#method.is_ascii) functions - an empty string or slice also returns `true`.

This follows the pattern of [`all()`](https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.all). Clippy currently suggests to change `string.chars().all(|c| c.is_ascii())` into `string.is_ascii()`. This suggestion therefore seems fitting.

I've already questioned the behavior for this multiple times. I've always had to check the internals to conclude how it works. That's why I'm opening this PR to add it directly in the documentation.
2025-10-16 19:35:28 +02:00
Matthias Krüger
334b3af42c
Rollup merge of #144438 - dawidl022:contracts/guarded-lowering, r=oli-obk
Guard HIR lowered contracts with `contract_checks`

Refactor contract HIR lowering to ensure no contract code is executed when contract-checks are disabled.

The call to `contract_checks` is moved to inside the lowered fn body, and contract closures are built conditionally, ensuring no side-effects present in contracts occur when those are disabled. This partially addresses rust-lang/rust#139548, i.e. the bad behavior no longer happens with contract checks disabled (`-Zcontract-checks=no`).

The change is made in preparation for adding contract variable declarations - variables declared before the `requires` assertion, and accessible from both `requires` and `ensures`, but not in the function body (PR rust-lang/rust#144444). As those declarations may also have side-effects, it's good to guard them with `contract_checks` - the new lowering approach allows for this to be done easily.

Contracts tracking issue: rust-lang/rust#128044

**Known limiatations**:

- It is still possible to early return from the *function* from within a contract, e.g.

  ```rust
  #[ensures({if x > 0 { return 0 }; |_| true})]
  fn foo(x: u32) -> i32 {
      42
  }
  ```

  When `foo` is called with an argument greater than 0, instead of `42`, `0` will be returned.

  As this is not a regression, it is not addressed in this PR. However, it may be worth revisiting later down the line, as users may expect a form of early return from *contract specifications*, and so returning from the entire *function* could cause confusion.

- ~Contracts are still not optimised out when disabled. Currently, even when contracts are disabled, the code generated causes existing optimisations to fail, meaning even disabled contracts could impact runtime performance. This issue is blocking rust-lang/rust#136578, and has not been addressed in this PR, i.e. the `mir-opt` and `codegen` tests that fail in rust-lang/rust#136578 still fail with these new HIR lowering changes.~ Contracts should now be optimised out when disabled, however some regressions tests still need to be added to be sure that is indeed the case.
2025-10-16 19:35:22 +02:00
timvisee
7a11c72db0
is_ascii on an empty string or slice returns true 2025-10-16 10:52:51 +02:00
bors
402ce0ef07 Auto merge of #147745 - matthiaskrgr:rollup-b4kftk9, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#143191 (Stabilize `rwlock_downgrade` library feature)
 - rust-lang/rust#147444 (Allow printing a fully-qualified path in `def_path_str`)
 - rust-lang/rust#147527 (Update t-compiler beta nomination Zulip msg)
 - rust-lang/rust#147670 (some `ErrorGuaranteed` cleanups)
 - rust-lang/rust#147676 (Return spans out of `is_doc_comment` to reduce reliance on `.span()` on attributes)
 - rust-lang/rust#147708 (const `mem::drop`)
 - rust-lang/rust#147710 (Fix ICE when using contracts on async functions)
 - rust-lang/rust#147716 (Fix some comments)
 - rust-lang/rust#147718 (miri: use allocator_shim_contents codegen helper)
 - rust-lang/rust#147729 (ignore boring locals when explaining why a borrow contains a point due to drop of a live local under polonius)
 - rust-lang/rust#147742 (Revert unintentional whitespace changes to rustfmt-excluded file)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-10-15 23:20:53 +00:00
Matthias Krüger
9bd8aa5e7c
Rollup merge of #147708 - clarfonthey:const-drop, r=oli-obk
const `mem::drop`

I'm putting this under the `const Destruct` feature flag since it doesn't really feel relevant to put it elsewhere… it's just an empty function body, so, it doesn't have any particular weirdness attached to it (unlike `drop_in_place`, for example).

r? wg-const-eval
2025-10-15 23:41:04 +02:00
bors
57ef8d642d Auto merge of #144064 - davidtwco:prefer-alias-over-env-for-sizedness, r=lcnr
prefer alias candidates for sizedness + auto trait goals

Fixes rust-lang/rust#143992

- abd07dec44437554520453f929c2b12d4eb8b11e: Reverts rust-lang/rust#144016 so that `MetaSized` bounds are checked properly, and updates all the tests accordingly, including making `tests/ui/sized-hierarchy/incomplete-inference-issue-143992.rs` fail when it shouldn't
- 90e61db9745f53d9aef21e3ebce0df19cc1389d7: Prefer alias candidates over parameter environment candidates for sizedness, auto and default traits. `tests/ui/sized-hierarchy/incomplete-inference-issue-143992.rs` passes again, but `tests/ui/generic-associated-types/issue-93262.rs` starts failing when it shouldn't
- e412062171925d0b40fdbeb5765c45087bdf0fe7: No longer require that predicates of aliases hold in well-formedness checking of the alias. `tests/ui/generic-associated-types/issue-93262.rs` passes again

Each commit updates all the tests to their new output so it should be easy enough to see what the impact of each change individually is. After all of the changes, tests that pass when they didn't before or vice versa:

- `tests/ui/extern/extern-types-size_of_val.rs`
    - Previously passing, but only because of rust-lang/rust#144016, now correctly errors
- `tests/ui/sized-hierarchy/incomplete-inference-issue-143992.rs`
    - Previously failing on next solver, only because rust-lang/rust#144016 only applied to the old solver, passing now with 90e61db9745f53d9aef21e3ebce0df19cc1389d7
- `tests/ui/sized-hierarchy/overflow.rs`
    - Previously passing, but only because of rust-lang/rust#144016, now correctly errors
- `tests/ui/generic-associated-types/issue-92096.rs`
    - Previously passing, due to e412062171925d0b40fdbeb5765c45087bdf0fe7
    - Fails to prove `C::Connecting<'placeholder>: Send` which is required when proving that the generator is `Send`. This is an instance of rust-lang/rust#110338.
- `tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.rs`
    - Previously passing, now failing in the next solver, due to 03e0fdab6196e81b44356f42f03b6a0a224cf451
    - Expected that this test now fails as ambigious, see [Zulip](https://rust-lang.zulipchat.com/#narrow/channel/144729-t-types/topic/sizedness.20bounds.20in.20explicit_implied_predicates_of.20.28.23142712.29/near/526987384)

This had a crater run in https://github.com/rust-lang/rust/pull/142712#issuecomment-3050358772 alongside some other changes.

r? `@lcnr`
cc rust-lang/rust#142712 (this extracts part of that change)
2025-10-15 20:15:46 +00:00
David Wood
519d6cd364
core: relax supertrait of Destruct 2025-10-15 09:40:44 +01:00
Matthias Krüger
ed6077ab18
Rollup merge of #147711 - saethlin:GlobalAlloc-safety, r=Amanieu
Clarify that UB will occur, not can/may in GlobalAlloc docs

These doc comments start out very clear by saying the caller "must" or "has to" ensure something, but the end with some form of "otherwise undefined behavior may result" which sounds like it is implementation-defined and seems to conflict with the way the paragraph starts. Consistent phrasing makes it clearer that when the safety precondition is violated, UB is encountered.

Some of the phrasing here is a bit awkward to me, I don't think we usually say "the behavior is undefined" `@RalfJung` right? But in either case I'm trying to be surgical in my edit here.

r? Amanieu
2025-10-15 07:09:57 +02:00
Matthias Krüger
8509756f46
Rollup merge of #146841 - bjoernager:const-slice-rotate, r=Amanieu
Stabilise `rotate_left` and `rotate_right` in `[_]` as `const fn` items.

Tracking issue: rust-lang/rust#143812

Closes: rust-lang/rust#143812

This PR stabilises the `const_slice_rotate` feature:

```rust
impl<T> [T] {
    pub const fn rotate_left(&mut self, mid: usize);

    pub const fn rotate_right(&mut self, k: usize);
}
```

No blockers or unresolved questions. FCP required.

Courtesy of `@okaneco.`
2025-10-15 07:09:54 +02:00
ltdk
491bc5008c const mem::drop 2025-10-14 21:49:24 -04:00
Ben Kimock
72396d9f18 Clarify that UB will occur, not can/may in GlobalAlloc docs 2025-10-14 21:12:11 -04:00
Matthias Krüger
49be94c392
Rollup merge of #147666 - Kivooeo:full_mud_add-followup, r=scottmcm
Replace manual implementation with `carrying_mul_add`

cc https://github.com/rust-lang/rust/pull/146277#discussion_r2427778317

r? scottmcm
2025-10-14 19:47:31 +02:00
Matthias Krüger
252974a717
Rollup merge of #146187 - clarfonthey:const-drop-in-place, r=oli-obk
Unstably constify `ptr::drop_in_place` and related methods

Tracking: rust-lang/rust#109342
Supercedes: rust-lang/rust#145725

Makes methods const:

* `core::ptr::drop_in_place`
* `core::mem::ManuallyDrop::drop`
* `core::mem::MaybeUninit::assume_init_drop`
* `<[core::mem::MaybeUninit<_>]>::assume_init_drop`
* `<*mut _>::drop_in_place`
* `core::ptr::NonNull::drop_in_place`
2025-10-14 19:47:28 +02:00
bors
e100792918 Auto merge of #147662 - Zalathar:rollup-j8ci0f2, r=Zalathar
Rollup of 12 pull requests

Successful merges:

 - rust-lang/rust#146277 (Enable `u64` limbs in `core::num::bignum`)
 - rust-lang/rust#146976 (constify basic Clone impls)
 - rust-lang/rust#147249 (Do two passes of `handle_opaque_type_uses_next`)
 - rust-lang/rust#147266 (fix 2 search graph bugs)
 - rust-lang/rust#147497 (`proc_macro` cleanups (3/N))
 - rust-lang/rust#147546 (Suppress unused_parens for labeled break)
 - rust-lang/rust#147548 (Fix ICE for never pattern as closure parameters)
 - rust-lang/rust#147594 (std: implement `pal::os::exit` for VEXos)
 - rust-lang/rust#147596 (Adjust the Arm targets in CI to reflect latest changes)
 - rust-lang/rust#147607 (GVN: Invalidate derefs at loop headers)
 - rust-lang/rust#147620 (Avoid redundant UB check in RangeFrom slice indexing)
 - rust-lang/rust#147647 (Hide vendoring and copyright in GHA group)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-10-14 12:32:31 +00:00
Kivooeo
714843dc57 replace manual implementation with carrying_mul_add 2025-10-14 06:13:22 +00:00
Stuart Cook
4a67c015bd
Rollup merge of #147620 - saethlin:RangeFrom-noubcheck, r=scottmcm
Avoid redundant UB check in RangeFrom slice indexing

I noticed this while picking through the IR we generate for https://github.com/rust-lang/rust/pull/134938. I think we just forgot to apply this trick to `RangeFrom`?
2025-10-14 16:31:02 +11:00
Stuart Cook
ed290fdd5c
Rollup merge of #146976 - npmccallum:clone, r=scottmcm
constify basic Clone impls
2025-10-14 16:30:56 +11:00
Stuart Cook
6e07b25bf0
Rollup merge of #146277 - Kivooeo:u64-unlock, r=scottmcm
Enable `u64` limbs in `core::num::bignum`

Since `u128` is stable now, I guess, we can safely add this, not sure if this requires tests or anything

cc https://github.com/rust-lang/rust/issues/137887
2025-10-14 16:30:56 +11:00
bors
fb24b04b09 Auto merge of #147353 - the8472:nondrop-array-iter, r=scottmcm
only call polymorphic array iter drop machinery when the type requires it

I saw a bunch of dead, empty  `<[core::mem::maybe_uninit::MaybeUninit<T>; N] as core::array::iter::iter_inner::PartialDrop>::partial_drop` functions when compiling with more than 1 CGU.

Let's see if we can help optimizations to eliminate stuff earlier.

r? ghost
2025-10-14 05:29:24 +00:00
Guillaume Gomez
b7ea44a49d
Rollup merge of #147605 - Zalathar:from-str-radix, r=Mark-Simulacrum
Add doc links between `{integer}::from_str_radix` and `from_str`

When parsing base-10 numbers, it's easy to miss `<Self as FromStr>::from_str` and `str::parse` as potential alternatives to `from_str_radix`.

- A similar suggestion is given by https://rust-lang.github.io/rust-clippy/master/index.html#from_str_radix_10
2025-10-13 11:25:22 +02:00
Ben Kimock
4f1b945a49 Avoid redundant UB check in RangeFrom slice indexing 2025-10-12 19:12:15 -04:00
Zalathar
2be88e39ea Add doc links between {integer}::from_str_radix and from_str 2025-10-12 22:54:50 +11:00
Matthias Krüger
817720c9a9
Rollup merge of #138799 - joboet:extend-tuple, r=Mark-Simulacrum
core: simplify `Extend` for tuples

This is an alternative to https://github.com/rust-lang/rust/pull/137400. The current macro is incredibly complicated and introduces subtle bugs like calling the `extend_one` of the individual collections in backwards order. This PR drastically simplifies the macro by removing recursion and moving the specialization out of the macro. It also fixes the ordering issue described above (I've stolen the test of the new behaviour from https://github.com/rust-lang/rust/pull/137400). Additionally, the 1-tuple is now special-cased to allow taking advantage of the well-optimized `Extend` implementations of the individual collection.
2025-10-12 10:13:12 +02:00
bors
3be68033b6 Auto merge of #145513 - beepster4096:erasedereftemps, r=saethlin,cjgillot
Validate CopyForDeref and DerefTemps better and remove them from runtime MIR

(split from my WIP rust-lang/rust#145344)

This PR:
- Removes `Rvalue::CopyForDeref` and `LocalInfo::DerefTemp` from runtime MIR
    - Using a new mir pass `EraseDerefTemps`
    - `CopyForDeref(x)` is turned into `Use(Copy(x))`
    - `DerefTemp` is turned into `Boring`
        - Not sure if this part is actually necessary, it made more sense in rust-lang/rust#145344 with `DerefTemp` storing actual data that I wanted to keep from having to be kept in sync with the rest of the body in runtime MIR
- Checks in validation that `CopyForDeref` and `DerefTemp` are only used together
- Removes special handling for `CopyForDeref` from many places
- Removes `CopyForDeref` from `custom_mir` reverting rust-lang/rust#111587
    - In runtime MIR simple copies can be used instead
    - In post cleanup analysis MIR it was already wrong to use due to the lack of support for creating `DerefTemp` locals
    - Possibly this should be its own PR?
 - Adds an argument to `deref_finder` to avoid creating new `DerefTemp`s and `CopyForDeref` in runtime MIR.
     - Ideally we would just avoid making intermediate derefs instead of fixing it at the end of a pass / during shim building
 - Removes some usages of `deref_finder` that I found out don't actually do anything

r? oli-obk
2025-10-12 02:34:20 +00:00
beepster4096
2da55cdb2c remove copyforderef from custom_mir
it did not create DerefTemp locals when used, so it was never actually correct.
2025-10-10 20:30:19 -07:00
Dawid Lachowicz
2a5dac7682
Remove no longer used contract_checks intrinsic
The contract_checks compiler flag is now used to determine
if runtime contract checks should be enabled, as opposed
to the compiler intrinsic as previously.
2025-10-11 00:16:44 +01:00
Dawid Lachowicz
e4ead0ec70
Guard HIR lowered contracts with contract_checks
Refactor contract HIR lowering to ensure no contract code is
executed when contract-checks are disabled.

The call to contract_checks is moved to inside the lowered fn
body, and contract closures are built conditionally, ensuring
no side-effects present in contracts occur when those are disabled.
2025-10-11 00:16:29 +01:00
dianqk
ab7d63afca
Rollup merge of #147562 - tyilo:stabilize-unsigned_nonzero_div_ceil, r=joboet
Stabilize `NonZero<u*>::div_ceil`

As per https://github.com/rust-lang/rust/issues/132968#issuecomment-3390765077

r? libs
2025-10-11 07:06:01 +08:00
dianqk
38a5143396
Rollup merge of #147551 - folkertdev:is-multiple-of-overflow-checks, r=Amanieu
remove `#[rustc_inherit_overflow_checks]` from `is_multiple_of`

Most likely this was just a result of copy-pasting. The attribute has no effect, because `%` always uses overflow checks.

r? `@Amanieu`
cc `@RalfJung`
2025-10-11 07:05:59 +08:00
Asger Hautop Drewsen
4eccd02229 Stabilize unsigned_nonzero_div_ceil 2025-10-10 18:18:27 +02:00
Camille Gillot
b7c2b3dc80 Remove StatementKind::Deinit. 2025-10-10 12:57:24 +00:00
Folkert de Vries
5ab4e18dfc
remove #[rustc_inherit_overflow_checks] from is_multiple_of 2025-10-10 12:51:41 +02:00
Stuart Cook
9ace0de26b
Rollup merge of #147489 - chenyukang:yukang-prefer-repeat-n, r=Kivooeo,oli-obk
Prefer to use repeat_n over repeat().take()

More from https://github.com/rust-lang/rust/pull/147464, but batch processed with `ast-grep` to find and replace.

second commit add notes for library: affaf532f9

r? ``@RalfJung``
2025-10-09 18:43:26 +11:00
Stuart Cook
8e363d32ae
Rollup merge of #147470 - ia0:immediate-abort, r=Mark-Simulacrum
Clarify how to remediate the panic_immediate_abort error

Users who build `core` for the sole purpose of enabling `panic_immediate_abort` might expect "`panic_immediate_abort` is now a real panic strategy" to mean that setting `panic = "immediate-abort"` in `Cargo.toml` or `-Cpanic=immediate-abort` in `RUSTFLAGS` to be sufficient for migration. But this is not the case, `core` still needs to be built for those changes to take effect.

See https://github.com/rust-lang/rust/issues/146974 for additional context.

See https://github.com/rust-lang/rust/issues/147286 and https://github.com/rust-lang/cargo/issues/16042 for the revelant tracking issues.
2025-10-09 18:43:24 +11:00
Stuart Cook
4e3e7ce078
Rollup merge of #147457 - the8472:slice_fill_memset2, r=RalfJung,joboet
specialize slice::fill to use memset when possible

It helps const eval performance https://github.com/rust-lang/miri/issues/4616, debug builds and the gcc backend.

Previously attempted in https://github.com/rust-lang/rust/pull/83245 but reverted due to unsoundness https://github.com/rust-lang/rust/issues/87891 around potentially-uninitialized types. This PR only handles primitives where the problem does not arise.

split off from https://github.com/rust-lang/rust/pull/147294
2025-10-09 18:43:22 +11:00
Stuart Cook
473a74a410
Rollup merge of #147420 - samueltardieu:diag-items/consts-mod, r=joboet
Add diagnostic items for `pub mod consts` of FP types

They will be used in Clippy.
2025-10-09 18:43:22 +11:00
The 8472
99ab27f90c specialize slice::fill to use memset when possible
LLVM generally can do this on its own, but it helps miri and other backends.
2025-10-08 20:14:24 +02:00
yukang
affaf532f9 referring to repeat_n in std::iter::repeat 2025-10-09 01:25:32 +08:00
Julien Cretin
594f9c6c4f Clarify how to remediate the panic_immediate_abort error
Users who build `core` for the sole purpose of enabling `panic_immediate_abort` might expect
"`panic_immediate_abort` is now a real panic strategy" to mean that setting `panic =
"immediate-abort"` in `Cargo.toml` or `-Cpanic=immediate-abort` in `RUSTFLAGS` to be sufficient for
migration. But this is not the case, `core` still needs to be built for those changes to take
effect.

See https://github.com/rust-lang/rust/issues/146974 for additional context.
2025-10-08 11:35:39 +02:00
bors
d62f33a7c6 Auto merge of #147449 - matthiaskrgr:rollup-njyi5yr, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#145943 (stdlib docs: document lifetime extension for `format_args!`'s arguments)
 - rust-lang/rust#147243 (cmse: disallow `impl Trait` in `cmse-nonsecure-entry` return types)
 - rust-lang/rust#147402 ([rustdoc] Don't serialize & deserialize data that doesn't go OTW)
 - rust-lang/rust#147418 (Fix target list of `link_section`)
 - rust-lang/rust#147429 (Print tip for human error format in runtest)
 - rust-lang/rust#147441 (Fix comments error for Provenance impls)
 - rust-lang/rust#147442 (c-variadic: fix thir-print for `...` without a pattern)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-10-07 17:37:56 +00:00
Marijn Schouten
d52744e9fc iter repeat: panic on last 2025-10-07 16:43:48 +00:00
Matthias Krüger
bce59abf1e
Rollup merge of #145943 - dianne:format-args-assign-docs, r=joboet
stdlib docs: document lifetime extension for `format_args!`'s arguments

Since rust-lang/rust#140748 is stable and rust-lang/rust#92698 is closed, the section about `format_args!`'s argument lifetime limitation is outdated. I've updated it to point to the Reference docs, which will specify lifetime extension rules for builtin macros once rust-lang/reference#1980 or equivalent is merged.

I've also taken the liberty of updating one of the doctests to assign the result of `format_args!` to a variable, both to provide an example and because I think it reads a little better.

r? `@m-ou-se`
2025-10-07 17:42:10 +02:00