Commit Graph

2711 Commits

Author SHA1 Message Date
bors
d7df5bdf29 Auto merge of #140464 - oli-obk:successors-mut-perf, r=petrochenkov
Use a closure instead of three chained iterators

Fixes the perf regression from #123948

That PR had chained a third option to the iterator which apparently didn't optimize well
2025-05-03 10:43:38 +00:00
Matthias Krüger
3648f3aa77
Rollup merge of #140458 - azhogin:azhogin/async-drop-fix-dropped-tuple-ice, r=oli-obk
Fix for async drop ice with partly dropped tuple

Fixes https://github.com/rust-lang/rust/issues/140427.
Problem was with block data access with block id from new added blocks in patch.
2025-04-30 22:36:39 +02:00
bors
0fbb922e53 Auto merge of #140023 - cjgillot:arena-try-alloc, r=BoxyUwU
Introduce Arena::try_alloc_from_iter.

`alloc_from_iter` already collects the iterator for reentrancy. So adding an early exit for a fallible iterator integrates naturally into the code. This avoids the other solution to allocate and dump the allocation.
2025-04-29 21:06:15 +00:00
Oli Scherer
9193dfe435 Use a closure instead of three chained iterators 2025-04-29 14:58:21 +00:00
Andrew Zhogin
cce706ec3c Fix for async drop ice with partly dropped tuple 2025-04-29 21:41:15 +07:00
Oli Scherer
820fce61e7 Some style nits 2025-04-29 14:03:06 +00:00
bors
4c83e55e2d Auto merge of #137940 - 1c3t3a:alignment-borrows-check, r=saethlin
Extend the alignment check to borrows

The current alignment check does not include checks for creating misaligned references from raw pointers, which is now added in this patch.

When inserting the check we need to be careful with references to field projections (e.g. `&(*ptr).a`), in which case the resulting reference must be aligned according to the field type and not the type of the pointer.

r? `@saethlin`

cc `@RalfJung,` after our discussion in #134424
2025-04-29 05:36:44 +00:00
Bastian Kersting
7082fa27a7 Rework the logic for PointerFinder::visit_place
This makes the implementation of our PointerFinder a bit more
straightforward.
2025-04-28 12:36:47 +00:00
Andrew Zhogin
c366756a85 AsyncDrop implementation using shim codegen of async_drop_in_place::{closure}, scoped async drop added. 2025-04-28 16:23:13 +07:00
Andrew Zhogin
52c1838fa7 dropee_emit_retag function separated in drop glue build 2025-04-28 00:52:30 +07:00
bors
43e62a789c Auto merge of #140288 - Zalathar:new-executor, r=jieyouxu
compiletest: Re-land using the new non-libtest executor by default

This PR re-lands #139998, which had the misfortune of triggering download-rustc in its CI jobs, so we didn't get proper test metrics for comparison with the old implementation. So that was PR was reverted in #140233, with the intention of re-landing it alongside a dummy compiler change to inhibit download-rustc.

---

Original PR description for #139998:
>The new executor was implemented in #139660, but required a manual opt-in. This PR activates the new executor by default, but leaves the old libtest-based executor in place (temporarily) to make reverting easier if something unexpectedly goes horribly wrong.
>
>Currently the new executor can be explicitly disabled by passing the `-N` flag to compiletest (e.g. `./x test ui -- -N`), but eventually that flag will be removed, alongside the removal of the libtest dependency. The flag is mostly there to make manual comparative testing easier if something does go wrong.
>
>As before, there *should* be no user-visible difference between the old executor and the new executor.

---
r? jieyouxu
2025-04-26 22:33:56 +00:00
bors
d3508a8ad0 Auto merge of #140177 - tmandry:compiletest-par, r=jieyouxu
[compiletest] Parallelize test discovery

Certain filesystems are slow to service individual read requests, but can service many in parallel. This change brings down the time to run a single cached test on one of those filesystems from 40s to about 8s.
2025-04-26 02:03:54 +00:00
bors
b4c8b0c3f0 Auto merge of #140298 - matthiaskrgr:rollup-5tc1gvb, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #137683 (Add a tidy check for GCC submodule version)
 - #138968 (Update the index of Result to make the summary more comprehensive)
 - #139572 (docs(std): mention const blocks in const keyword doc page)
 - #140152 (Unify the format of rustc cli flags)
 - #140193 (fix ICE in `#[naked]` attribute validation)
 - #140205 (Tidying up UI tests [2/N])
 - #140284 (remove expect() in `unnecessary_transmutes`)
 - #140290 (rustdoc: fix typo change from equivelent to equivalent)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-25 18:51:15 +00:00
Bastian Kersting
a3e7c699bc Extend the alignment check to borrows
The current alignment check does not include checks for creating
misaligned references from raw pointers, which is now added in this
patch.

When inserting the check we need to be careful with references to
field projections (e.g. `&(*ptr).a`), in which case the resulting
reference must be aligned according to the field type and not the
type of the pointer.
2025-04-25 12:16:40 +00:00
bendn
d3a4ebca85
remove expect() in unnecessary_transmutes 2025-04-25 19:07:41 +07:00
Zalathar
1670de40e0 Trivial compiler change to inhibit download-rustc in CI 2025-04-25 20:41:50 +10:00
Matthias Krüger
564e5ccb5c
Rollup merge of #140202 - est31:let_chains_feature_compiler, r=lcnr
Make #![feature(let_chains)] bootstrap conditional in compiler/

Let chains have been stabilized recently in #132833, so we can remove the gating from our uses in the compiler (as the compiler uses edition 2024).
2025-04-25 07:50:25 +02:00
Matthias Krüger
53afa97eb7
Rollup merge of #136083 - bend-n:⃤⃤, r=lcnr
Suggest {to,from}_ne_bytes for transmutations between arrays and integers, etc

implements #136067

Rust has helper methods for many kinds of safe transmutes, for example integer<->bytes. This is a lint against using transmute for these cases.

```rs
fn bytes_at_home(x: [u8; 4]) -> u32 {
   transmute(x)
}

// other examples
transmute::<[u8; 2], u16>();
transmute::<[u8; 8], f64>();
transmute::<u32, [u8; 4]>();
transmute::<char, u32>();
transmute::<u32, char>();
```
It would be handy to suggest `u32::from_ne_bytes(x)`.
This is implemented for `[u8; _]` -> `{float int}`

This also implements the cases:
`fXX` <-> `uXX` = `{from_bits, to_bits}`
`uXX` -> `iXX` via `cast_unsigned` and `cast_signed`
{`char` -> `u32`, `bool` -> `n8`} via `from`
`u32` -> `char` via `from_u32_unchecked` (note: notes `from_u32().unwrap()`) (contested)
`u8` -> `bool` via `==` (debatable)

---
try-job: aarch64-gnu
try-job: test-various
2025-04-24 17:19:42 +02:00
Zalathar
f673c9b056 Trivial compiler change to inhibit download-rustc in CI 2025-04-24 19:44:13 +10:00
Matthias Krüger
a8ebfb256a
Rollup merge of #139261 - RalfJung:msvc-align-mitigation, r=oli-obk
mitigate MSVC alignment issue on x86-32

This implements mitigation for https://github.com/rust-lang/rust/issues/112480 by stopping to emit `align` attributes on loads and function arguments when building for a win32 MSVC target. MSVC is known to not properly align `u64` and similar types, and claiming to LLVM that everything is properly aligned increases the chance that this will cause problems.

Of course, the misalignment is still a bug, but we can't fix that bug, only MSVC can.

Also add an errata note to the platform support page warning users about this known problem.

try-job: `i686-msvc*`
2025-04-24 11:40:35 +02:00
bendn
c8c074288a
Suggest {to,from}_ne_bytes for transmutations between arrays and integers, etc 2025-04-24 13:14:36 +07:00
est31
7493e1cdf6 Make #![feature(let_chains)] bootstrap conditional in compiler/ 2025-04-23 16:40:30 +02:00
Chris Denton
b03267fc11
Rollup merge of #140160 - oli-obk:lang-items, r=jieyouxu
Use `is_lang_item` and `as_lang_item` instead of handrolling their logic

Various cleanups and deduplication. Most notably `if is_lang_item(foo, bar) {} else if is_lang_item...` chains are turned into matches. No behaviour changes intended beyond turning ICEs into fatal "lang item not found" errors
2025-04-23 00:43:07 +00:00
Oli Scherer
5d2952100f Use is_lang_item and as_lang_item instead of handrolling their logic 2025-04-22 11:02:37 +00:00
Nicholas Nethercote
521b379705 Remove unnecessary lifetime on ResultsVisitor. 2025-04-22 10:08:05 +10:00
Chris Denton
98515864d2
Rollup merge of #140024 - cjgillot:continue-jumping, r=compiler-errors
Remove early exits from JumpThreading.

This removes early exits from https://github.com/rust-lang/rust/pull/131203 as I asked during review.

The correctness of the backtracking is `mutated_statement` clearing all relevant conditions. If `process_statement` fails to insert a new condition, for instance by const-eval failure, `mutated_statement`  still removes the obsolete conditions from the state.

r? `@compiler-errors`
2025-04-19 19:30:49 +00:00
Chris Denton
5d2375f789
Rollup merge of #139042 - compiler-errors:do-not-optimize-switchint, r=saethlin
Do not remove trivial `SwitchInt` in analysis MIR

This PR ensures that we don't prematurely remove trivial `SwitchInt` terminators which affects both the borrow-checking and runtime semantics (i.e. UB) of the code. Previously the `SimplifyCfg` optimization was removing `SwitchInt` terminators when they was "trivial", i.e. when all arms branched to the same basic block, even if that `SwitchInt` terminator had the side-effect of reading an operand which (for example) may not be initialized or may point to an invalid place in memory.

This behavior is unlike all other optimizations, which are only applied after "analysis" (i.e. borrow-checking) is finished, and which Miri disables to make sure the compiler doesn't silently remove UB.

Fixing this code "breaks" (i.e. unmasks) code that used to borrow-check but no longer does, like:

```rust
fn foo() {
    let x;
    let (0 | _) = x;
}
```

This match expression should perform a read because `_` does not shadow the `0` literal pattern, and the compiler should have to read the match scrutinee to compare it to 0. I've checked that this behavior does not actually manifest in practice via a crater run which came back clean: https://github.com/rust-lang/rust/pull/139042#issuecomment-2767436367

As a side-note, it may be tempting to suggest that this is actually a good thing or that we should preserve this behavior. If we wanted to make this work (i.e. trivially optimize out reads from matches that are redundant like `0 | _`), then we should be enabling this behavior *after* fixing this. However, I think it's kinda unprincipled, and for example other variations of the code don't even work today, e.g.:

```rust
fn foo() {
    let x;
    let (0.. | _) = x;
}
```
2025-04-19 19:30:46 +00:00
Camille GILLOT
d0d3021bf8 Introduce Arena::try_alloc_from_iter. 2025-04-19 01:13:18 +00:00
Camille GILLOT
bd5c43835a Remove early exits from JumpThreading. 2025-04-18 23:34:37 +00:00
Matthias Krüger
67e2358fbb
Rollup merge of #139902 - lcnr:no-opaque-cast-projection, r=oli-obk
do not emit `OpaqueCast` projections with `-Znext-solver`

We normalize opaque types in their defining scope if the new solver is enabled. This means projections do not contain any 'revealable' opaque types we need to worry about. We either have a type which has been normalized by writeback or we need to normalize it anyways.

r? ```@compiler-errors``` ```@oli-obk```
2025-04-17 17:40:28 +02:00
lcnr
289a23e0e2 do not emit OpaqueCast projections with -Znext-solver 2025-04-17 12:15:04 +02:00
Jake Goulding
0117884917 Move eager translation to a method on Diag
This will allow us to eagerly translate messages on a top-level
diagnostic, such as a `LintDiagnostic`. As a bonus, we can remove the
awkward closure passed into Subdiagnostic and make better use of
`Into`.
2025-04-16 21:38:59 -04:00
bors
f433fa46b0 Auto merge of #139845 - Zalathar:rollup-u5u5y1v, r=Zalathar
Rollup of 17 pull requests

Successful merges:

 - #138374 (Enable contracts for const functions)
 - #138380 (ci: add runners for vanilla LLVM 20)
 - #138393 (Allow const patterns of matches to contain pattern types)
 - #139517 (std: sys: process: uefi: Use NULL stdin by default)
 - #139554 (std: add Output::exit_ok)
 - #139660 (compiletest: Add an experimental new executor to replace libtest)
 - #139669 (Overhaul `AssocItem`)
 - #139671 (Proc macro span API redesign: Replace proc_macro::SourceFile by Span::{file, local_file})
 - #139750 (std/thread: Use default stack size from menuconfig for NuttX)
 - #139772 (Remove `hir::Map`)
 - #139785 (Let CStrings be either 1 or 2 byte aligned.)
 - #139789 (do not unnecessarily leak auto traits in item bounds)
 - #139791 (drop global where-bounds before merging candidates)
 - #139798 (normalize: prefer `ParamEnv` over `AliasBound` candidates)
 - #139822 (Fix: Map EOPNOTSUPP to ErrorKind::Unsupported on Unix)
 - #139833 (Fix some HIR pretty-printing problems)
 - #139836 (Basic tests of MPMC receiver cloning)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-15 08:02:23 +00:00
Stuart Cook
13cd5256ac
Rollup merge of #139669 - nnethercote:overhaul-AssocItem, r=oli-obk
Overhaul `AssocItem`

`AssocItem` has multiple fields that only make sense some of the time. E.g. the `name` can be empty if it's an RPITIT associated type. It's clearer and less error prone if these fields are moved to the relevant `kind` variants.

r? ``@fee1-dead``
2025-04-15 15:47:27 +10:00
Nicholas Nethercote
78599d83e7 Move name field from AssocItem to AssocKind variants.
To accurately reflect that RPITIT assoc items don't have a name. This
avoids the use of `kw::Empty` to mean "no name", which is error prone.

Helps with #137978.
2025-04-15 08:07:15 +10:00
Matthias Krüger
04d10520f0
Rollup merge of #139811 - yotamofek:pr/newtype_cleanups, r=oli-obk
Use `newtype_index!`-generated types more idiomatically

Continuation of sorts of #139674
Shouldn't affect anything, just makes some code simpler
2025-04-14 21:55:40 +02:00
Yotam Ofek
4b63362f3d Use newtype_index!-generated types more idiomatically 2025-04-14 16:17:06 +00:00
Matthias Krüger
143f5d7696
Rollup merge of #139767 - compiler-errors:www, r=oli-obk
Visit place in `BackwardIncompatibleDropHint` statement

Remove a weird hack from the `LocalUpdater` where we were manually visiting the place stored in a `StatementKind::BackwardIncompatibleDropHint` because the MIR visitor impls weren't doing so.

Also, clean up `BackwardIncompatibleDropHint`s in `CleanupPostBorrowck`, since they're not needed for runtime MIR.
2025-04-14 18:15:32 +02:00
bors
5961e5ba3d Auto merge of #139781 - jhpratt:rollup-qadsjvb, r=jhpratt
Rollup of 9 pull requests

Successful merges:

 - #138336 (Improve `-Z crate-attr` diagnostics)
 - #139636 (Encode dep node edge count as u32 instead of usize)
 - #139666 (cleanup `mir_borrowck`)
 - #139695 (compiletest: consistently use `camino::{Utf8Path,Utf8PathBuf}` throughout)
 - #139699 (Proactively update coroutine drop shim's phase to account for later passes applied during shim query)
 - #139718 (enforce unsafe attributes in pre-2024 editions by default)
 - #139722 (Move some things to rustc_type_ir)
 - #139760 (UI tests: migrate remaining compile time `error-pattern`s to line annotations when possible)
 - #139776 (Switch attrs to `diagnostic::on_unimplemented`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-14 07:07:54 +00:00
Nicholas Nethercote
ce2aa97cd6 Move has_self field to hir::AssocKind::Fn.
`hir::AssocItem` currently has a boolean `fn_has_self_parameter` field,
which is misplaced, because it's only relevant for associated fns, not
for associated consts or types. This commit moves it (and renames it) to
the `AssocKind::Fn` variant, where it belongs.

This requires introducing a new C-style enum, `AssocTag`, which is like
`AssocKind` but without the fields. This is because `AssocKind` values
are passed to various functions like `find_by_ident_and_kind` to
indicate what kind of associated item should be searched for, and having
to specify `has_self` isn't relevant there.

New methods:
- Predicates `AssocItem::is_fn` and `AssocItem::is_method`.
- `AssocItem::as_tag` which converts `AssocItem::kind` to `AssocTag`.

Removed `find_by_name_and_kinds`, which is unused.

`AssocItem::descr` can now distinguish between methods and associated
functions, which slightly improves some error messages.
2025-04-14 16:13:04 +10:00
Jacob Pratt
c0ad72ef6a
Rollup merge of #139699 - compiler-errors:coroutine-drop-phase, r=scottmcm
Proactively update coroutine drop shim's phase to account for later passes applied during shim query

See comments in the pass and on test. Also see https://github.com/rust-lang/rust/pull/137264#issuecomment-2669706718.

Fixes https://github.com/rust-lang/rust/issues/137243
Fixes https://github.com/rust-lang/rust/issues/139698

r? scottmcm
2025-04-13 23:57:39 -04:00
bors
f836ae4e66 Auto merge of #124141 - nnethercote:rm-Nonterminal-and-TokenKind-Interpolated, r=petrochenkov
Remove `Nonterminal` and `TokenKind::Interpolated`

A third attempt at this; the first attempt was #96724 and the second was #114647.

r? `@ghost`
2025-04-14 03:56:55 +00:00
bors
15f58c46da Auto merge of #139766 - jhpratt:rollup-afrfmnk, r=jhpratt
Rollup of 10 pull requests

Successful merges:

 - #137043 (Initial `UnsafePinned` implementation [Part 1: Libs])
 - #138962 (Expect an array when expected and acutal types are both arrays during cast)
 - #139001 (add `naked_functions_rustic_abi` feature gate)
 - #139379 (Use delayed bug for normalization errors in drop elaboration)
 - #139582 (Various coercion cleanups)
 - #139628 (Suggest remove redundant `$()?` around `vis`)
 - #139644 (Micro-optimize `InstSimplify`'s `simplify_primitive_clone`)
 - #139674 (In `rustc_mir_transform`, iterate over index newtypes instead of ints)
 - #139740 (Convert `tests/ui/lint/dead-code/self-assign.rs` to a known-bug test)
 - #139741 (fix smir's run! doc and import)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-14 00:47:02 +00:00
Michael Goulet
2f96e784e2 Visit place in BackwardIncompatibleDropHint statement 2025-04-13 22:01:54 +00:00
Jacob Pratt
1b6fcd9440
Rollup merge of #139674 - yotamofek:pr/mir_transform/index-iterators, r=compiler-errors
In `rustc_mir_transform`, iterate over index newtypes instead of ints

Just makes code more idiomatic/easier to read, IMHO.
Also, some drive-by simplifications and cleanups.
2025-04-13 17:37:55 -04:00
Jacob Pratt
388d612765
Rollup merge of #139644 - yotamofek:pr/mir_transform/instsimplify/simplify_primitive_clone, r=compiler-errors
Micro-optimize `InstSimplify`'s `simplify_primitive_clone`

r? ````@compiler-errors```` , since you already did #139411 and got randomly selected for #139638 (feel free to reassign!)

Another one similar in spirit to #139411, but this time for `simplify_primitive_clone`, which is doing a bit of redundant work. Might not show up in benches, but probably worth micro-optimizing since the transformation is run even for debug builds.

See inline comments for my reasoning for making these changes.
2025-04-13 17:37:54 -04:00
Jacob Pratt
346d33a5b7
Rollup merge of #139379 - matthewjasper:drop-elab-normalization, r=compiler-errors
Use delayed bug for normalization errors in drop elaboration

Normalization can fail due to a lot of different earlier errors, so just use span_delayed_bug if normalization failed.

Closes #137287
Closes #135668

r? compiler-errors
2025-04-13 17:37:53 -04:00
clubby789
41a5d8ef3d JumpThreading: Bail out on interp errors 2025-04-13 20:29:51 +00:00
clubby789
9f35fe47c7 JumpThreading: Re-enable and fix Not ops on non-booleans 2025-04-13 20:29:49 +00:00
Michael Goulet
bc94c38d98 Proactively update coroutine drop shim's phase to account for later passes applied during shim query 2025-04-12 20:54:08 +00:00