Commit Graph

25590 Commits

Author SHA1 Message Date
bors 63b1dfc0e0 Auto merge of #156290 - JonathanBrouwer:rollup-PNM9rEm, r=JonathanBrouwer
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#156061 (Support `-Cpanic=unwind` on WASI targets)
 - rust-lang/rust#151753 (Experiment: Reborrow traits)
 - rust-lang/rust#156280 (Add regression test for closure return ICE)
 - rust-lang/rust#152487 (core: drop unmapped ZSTs in array `map`)
 - rust-lang/rust#153759 (Add a suite of ChunkedBitSet union/subtract/intersect test scenarios)
 - rust-lang/rust#156198 (Add `sync` option to `-Z threads` to force synchronization on one thread)
2026-05-07 23:03:11 +00:00
Jonathan Brouwer e56e388df9 Rollup merge of #156280 - TaKO8Ki:issue-155893-closure-return-ice, r=lqd
Add regression test for closure return ICE

Fixes rust-lang/rust#155893
2026-05-07 22:44:04 +02:00
Jonathan Brouwer 96e4153100 Rollup merge of #151753 - aapoalas:aapoalas/reborrow-and-coerce-shared-first-version, r=oli-obk
Experiment: Reborrow traits

With this PR we now have basic functional Reborrow and CoerceShared traits. The current limitations are:

1. Reborrowable types can only have one lifetime parameter, so as to avoid having to figure out and store in rmeta the information of which lifetimes weaken during reborrowing.
2. Reborrowing of `&mut` wrappers is working (though I've not tested generic wrappers like `Option<&mut T>` yet), but CoerceShared of `&mut` wrappers currently causes an ICE.

The remaining tasks to complete before I'd consider this PR mergeable are:

- [x] Fix ICE on CoerceShared. Unfortunately this might require dipping into rmeta.
- [x] Expand the tests to give a more complete view of the current state of the experiment.

Reborrow traits experiment: rust-lang/rust#145612

Co-authored by @dingxiangfei2009
2026-05-07 22:44:03 +02:00
Jonathan Brouwer 71597bc71c Rollup merge of #156061 - alexcrichton:unwinding-onw-asi, r=bjorn3
Support `-Cpanic=unwind` on WASI targets

This commit is some minor updates/restructuring in a few locations with the end result being supporting `-Cpanic=unwind` on WASI targets. This continues to be off-by-default insofar as WASI targets default to `-Cpanic=abort`, meaning that actually using anything in this commit requires `-Zbuild-std`. Specifically the changes made here are:

* The self-contained sysroot for WASI targets now contains a copy of `libunwind.a` from wasi-sdk, first shipped with wasi-sdk-33 (also updated here).
* The `unwind` crate here in this repository uses the `libunwind` module instead of the custom bare-metal wasm implementation of exceptions. This means that Rust uses the `_Unwind_*` symbols which allows it to interoperate with C/C++/etc.
* Wasm targets are all updated to pass the LLVM argument `-wasm-use-legacy-eh=false` to differ from LLVM's/clang's default of using the legacy exception handling proposal for WebAssembly. This has no effect by default because `panic=abort` is used on most targets. Emscripten is exempted from this as the Emscripten target is explicitly intended to follow LLVM's/clang's defaults.
* There's a single test in the test suite that links to the `panic_unwind` crate which ended up requiring `-Wexceptions` from Wasmtime, so the test parts were updated and Wasmtime was updated in CI, too.

The net result of all of this is that this should not actually affect any WebAssembly target's default behavior. Optionally, though, WASI programs can be built with exception handling via:

    RUSTFLAGS='-Cpanic=unwind' cargo +nightly run -Z build-std --target wasm32-wasip2

Effectively `-Zbuild-std` and `-Cpanic=unwind` is all that's necessary to enable this support on wasm targets.

Finally, this ends up closing rust-lang/rust#154593 as well. The WASI targets are now defined to use `-lunwind` to implement unwinding. This means that the in-tree definition of `__cpp_exception` is no longer of concern and the definition is always sourced externally. If Rust is linked with other C/C++ code using WASI then these idioms are compatible with wasi-sdk, for example, to use that as a linker. The main caveat is that when using an external linker the `-fwasm-exceptions` argument needs to be passed to `clang` for it to be able to find the `libunwind.a` library to link against.

Closes rust-lang/rust#154593
2026-05-07 22:44:02 +02:00
Alex Crichton 506693e7d6 Support -Cpanic=unwind on WASI targets
This commit is some minor updates/restructuring in a few locations with
the end result being supporting `-Cpanic=unwind` on WASI targets. This
continues to be off-by-default insofar as WASI targets default to
`-Cpanic=abort`, meaning that actually using anything in this commit
requires `-Zbuild-std`. Specifically the changes made here are:

* The self-contained sysroot for WASI targets now contains a copy of
  `libunwind.a` from wasi-sdk, first shipped with wasi-sdk-33 (also
  updated here).
* The `unwind` crate here in this repository uses the `libunwind` module
  instead of the custom bare-metal wasm implementation of exceptions.
  This means that Rust uses the `_Unwind_*` symbols which allows it to
  interoperate with C/C++/etc.
* Wasm targets are all updated to pass the LLVM argument
  `-wasm-use-legacy-eh=false` to differ from LLVM's/clang's default of
  using the legacy exception handling proposal for WebAssembly. This has
  no effect by default because `panic=abort` is used on most targets.
  Emscripten is exempted from this as the Emscripten target is
  explicitly intended to follow LLVM's/clang's defaults.
* There's a single test in the test suite that links to the
  `panic_unwind` crate which ended up requiring `-Wexceptions` from
  Wasmtime, so the test parts were updated and Wasmtime was updated in
  CI, too.

The net result of all of this is that this should not actually affect
any WebAssembly target's default behavior. Optionally, though, WASI
programs can be built with exception handling via:

    RUSTFLAGS='-Cpanic=unwind' cargo +nightly run -Z build-std --target wasm32-wasip2

Effectively `-Zbuild-std` and `-Cpanic=unwind` is all that's necessary
to enable this support on wasm targets.

Finally, this ends up closing 154593 as well. The WASI targets are now
defined to use `-lunwind` to implement unwinding. This means that the
in-tree definition of `__cpp_exception` is no longer of concern and the
definition is always sourced externally. If Rust is linked with other
C/C++ code using WASI then these idioms are compatible with wasi-sdk,
for example, to use that as a linker. The main caveat is that when using
an external linker the `-fwasm-exceptions` argument needs to be passed
to `clang` for it to be able to find the `libunwind.a` library to link
against.

Closes 154593
2026-05-07 12:51:29 -07:00
bors f964de49bc Auto merge of #149468 - chenyukang:yukang-fix-ice-149278, r=lcnr
Skipping borrowck because of trivial const



r? @saethlin

the [assertion](https://github.com/chenyukang/rust/blob/31c38576a4cf1a0864af536f62d11f829db1c7c8/compiler/rustc_mir_transform/src/lib.rs#L424) is added in PR: https://github.com/rust-lang/rust/pull/148040

I think we also need to skip trvial const in `mir_borrowck`.
2026-05-07 19:45:59 +00:00
Aapo Alasuutari 2d88ee87dd Reborrow traits 2026-05-07 21:55:44 +03:00
bors ffccab6abe Auto merge of #156278 - JonathanBrouwer:rollup-O8O1IcI, r=JonathanBrouwer
Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#146273 (lint ImproperCTypes: refactor linting architecture (part 2))
 - rust-lang/rust#154025 (Add `keepalive`, `set_keepalive` to `TcpStream` implementations)
 - rust-lang/rust#156024 (CFI: Fix LTO for `#![no_builtins]` crates with CFI)
 - rust-lang/rust#156243 (Move CrateInfo computation after codegen_crate)
 - rust-lang/rust#154846 (Add better default spans for the `Ty` impl of `QueryKey`)
 - rust-lang/rust#155220 (cg_clif: Don't show verbose run-make cmd output for passing tests)
 - rust-lang/rust#156204 (Implemented `PathBuf::into_string`)
 - rust-lang/rust#156245 (Move invocation_temp into OutputFilenames)
 - rust-lang/rust#156250 (add a few new solver normalization tests)
 - rust-lang/rust#156265 (Remove unused `ToStableHashKey` impls.)
2026-05-07 14:59:29 +00:00
Takayuki Maeda ddddb4d109 add regression test for closure return ICE 2026-05-07 23:33:00 +09:00
yukang 8e1f263f66 Skipping borrowck because of trivial const 2026-05-07 22:18:58 +08:00
Jonathan Brouwer 80af49a07f Rollup merge of #156250 - lqd:normalization-tests, r=lcnr
add a few new solver normalization tests

As discussed [on zulip](https://rust-lang.zulipchat.com/#narrow/channel/364551-t-types.2Ftrait-system-refactor/topic/ask.20for.20help/near/593097133), this PR adds the handful of new solver revisions and tests from https://github.com/rust-lang/trait-system-refactor-initiative/issues/139. Most cases that issue mentions were already fixed by https://github.com/rust-lang/rust/pull/140672 in 1.88, and some cases, we expect, by https://github.com/rust-lang/rust/pull/155767.

The issue about defaulted type parameters applies to both solvers and will be tracked in https://github.com/rust-lang/rust/issues/156271 instead.

Closes https://github.com/rust-lang/trait-system-refactor-initiative/issues/139.

r? lcnr
I'm not sure where the best place for the tests would be, do you have a better location in mind?
2026-05-07 14:13:55 +02:00
Jonathan Brouwer ce44b53e77 Rollup merge of #154846 - Zoxc:ty-def-span, r=lcnr
Add better default spans for the `Ty` impl of `QueryKey`

This add default spans for `Ty` in its implementation of `QueryKey`. This is useful so we can get spans for the `layout_of`  query which shows up in cycle errors.
2026-05-07 14:13:52 +02:00
Jonathan Brouwer c5941a03a2 Rollup merge of #156243 - bjorn3:lto_refactors18, r=mu001999
Move CrateInfo computation after codegen_crate

CrateInfo is only necessary during linking and non-local LTO.

Part of https://github.com/rust-lang/compiler-team/issues/908
2026-05-07 14:13:51 +02:00
Jonathan Brouwer 25494215e7 Rollup merge of #156024 - rcvalle:rust-cfi-fix-142284, r=bjorn3
CFI: Fix LTO for `#![no_builtins]` crates with CFI

Fixes LTO for `#![no_builtins]` crates with CFI enabled by using rustc's `EmitObj::Bitcode` path (and emitting LLVM bitcode in the `.o` for linker-based LTO).

It also adds tests that verify that the examples in [rust-cfi-examples](https://github.com/rcvalle/rust-cfi-examples) build and run with `-Zbuild-std` to prevent other future regressions.
2026-05-07 14:13:51 +02:00
bors 32bd660612 Auto merge of #156267 - jhpratt:rollup-xaL6466, r=jhpratt
Rollup of 12 pull requests

Successful merges:

 - rust-lang/rust#156173 (Fewer global node_id_to_def_id lookups)
 - rust-lang/rust#156177 (windows/time: avoid being too close to 0)
 - rust-lang/rust#155961 (Deny warnings in the test for crates that are available on stable)
 - rust-lang/rust#155981 (Use special DefIds for aliases)
 - rust-lang/rust#156130 (Fold/visit tweaks)
 - rust-lang/rust#156131 (Metadata macro/query cleanups)
 - rust-lang/rust#156202 (llvm: Use correct type for splat mask)
 - rust-lang/rust#156223 (Refactor `Type::size` field to `TypeId::size` method for `type_info`)
 - rust-lang/rust#156227 (Add Trusty OS to the generic error implementation.)
 - rust-lang/rust#156237 (compiletest: prevent directives from having multiple revisions)
 - rust-lang/rust#156241 (Move tests coercion)
 - rust-lang/rust#156258 (Document wasi-sdk minimum versions for WASI targets)
2026-05-07 11:51:24 +00:00
Rémy Rakic 130b1d881c move some normalization tests to the dedicated folder 2026-05-07 12:11:55 +02:00
Rémy Rakic 6cc6a63392 add normalization test with defaulted type param with diverging alias
Another example from https://github.com/rust-lang/trait-system-refactor-initiative/issues/139
and which was fixed in 1.89 `nightly-2025-06-18`.
2026-05-07 12:11:55 +02:00
Rémy Rakic 4922210ea6 add normalization test with field with diverging alias
Another example from https://github.com/rust-lang/trait-system-refactor-initiative/issues/139
and which was likely fixed by https://github.com/rust-lang/rust/pull/140672 as well.
2026-05-07 12:11:55 +02:00
Rémy Rakic e2ea0ba07a add new solver revisions to already fixed normalization tests
There were fixed by https://github.com/rust-lang/rust/pull/140672
2026-05-07 12:11:55 +02:00
Jacob Pratt 3d841c1702 Rollup merge of #156241 - danieljofficial:move-tests-coercion, r=Kivooeo
Move tests coercion

Hi, I have moved some tests that belong in the coercion folder. Please take out time to review
r? @Kivooeo
2026-05-07 02:12:15 -04:00
Jacob Pratt 44ce9e7758 Rollup merge of #156223 - SpriteOvO:type-info-refactor-size, r=oli-obk
Refactor `Type::size` field to `TypeId::size` method for `type_info`

Tracking issue rust-lang/rust#146922

r? @oli-obk
2026-05-07 02:12:12 -04:00
Jacob Pratt 70c1afd981 Rollup merge of #155961 - jdonszelmann:deny-warnings-stable, r=mejrs
Deny warnings in the test for crates that are available on stable

We've got a couple of crates, like `rustc_type_ir` that have parts disabled on stable. I believe part of this is so, for example, rust-analyzer can use bits of the compiler. We previously allowed warnings here, and I ran into one. This denies warnings in the test that compiles these stable crates (I chose not to on the crate itself, so you don't *constantly* run into the warnings if you have turned that off in `config.toml`). This test doesn't run by default, but it does run in CI.
2026-05-07 02:12:09 -04:00
bors 0e5924a4a0 Auto merge of #149509 - mu001999-contrib:flag/pub-as-pub-crate, r=jdonszelmann
Lint unused pub items in binary crates



~~This PR adds a new unstable flag -Ztreat-pub-as-pub-crate as [@Kobzol](https://github.com/Kobzol) suggested.~~
~~When compiling binary crates with this flag, the seed worklist will only contain the entry fn and won't contain other reachable items. Then we can do the dead code analysis for pub items just like they are pub(crate).~~

Related zulip thread [#general > pub/pub(crate) within a binary is a footgun](https://rust-lang.zulipchat.com/#narrow/channel/122651-general/topic/pub.2Fpub.28crate.29.20within.20a.20binary.20is.20a.20footgun/with/558931034).

---

Updated:

Adds a new lint `unused_pub_items_in_binary` (crate-level, default allow for now) instead of the previous unstable flag to lint unused `pub` items for binary crates.

See more details of implementation in https://github.com/rust-lang/rust/pull/149509#issuecomment-4102337689.

This lint is allowed by default, but I believe this has been better than the unstable flag. Making it warn-by-default will lead to a lot of noise for this PR (like bless many tests). So I'd like to make it warn-by-default in a separate PR in the future.
2026-05-07 05:38:32 +00:00
bors 4ddd4538a8 Auto merge of #154327 - WaffleLapkin:drop_in_place_ref, r=RalfJung,scottmcm,saethlin
change the type of the argument of `drop_in_place` lang item to `&mut _`



We used to special case `core::ptr::drop_in_place` when computing LLVM argument attributes with this hack:

https://github.com/rust-lang/rust/blob/db5e2dc248fe5bb26f70d7baec46a3bca9fa3e1d/compiler/rustc_ty_utils/src/abi.rs#L383-L392

This is because even though `drop_in_place` takes a `*mut T` it is semantically a `&mut T` (remember how `&mut Self` is passed to `Drop::drop`). This is apparently relevant for perf.

This PR replaces this hack with a simpler solution -- it makes `drop_in_place` a thin wrapper around newly added `core::ptr::drop_glue`, which is the actual lang item and takes a `&mut T`:

https://github.com/rust-lang/rust/blob/d2563d5003bbecff1efc40c1f5673ceec603825b/library/core/src/ptr/mod.rs#L810-L833

------

The rest of the PR is blessing tests and cleaning up things which are not necessary after this change.

One thing that is a bit awkward is that now that `drop_glue` is the actual lang item, a lot of the comments referring to `drop_in_place` are outdated. Should I try fixing that?

I've also changed `async_drop_in_place` to take a `&mut T`, and it simplified the code handling it a bit. (since it's unstable we don't need to introduce a wrapper)

-------

cc @RalfJung 
Closes https://github.com/rust-lang/rust/issues/154274
2026-05-07 00:52:53 +00:00
Ramon de C Valle acc33fe5dd CFI: Fix LTO for #![no_builtins] crates with CFI
Fixes LTO for `#![no_builtins]` crates with CFI enabled by using rustc's
`EmitObj::Bitcode` path (and emitting LLVM bitcode in the `.o` for
linker-based LTO).
2026-05-06 13:44:04 -07:00
Jonathan Brouwer 2744cb7ac6 Rollup merge of #156211 - kupiakos:space-in-hashbrown-src-location, r=wesleywiser
tests/ui: allow spaces in hashbrown src normalization

If one's home directory contains a space, the default location for the hashbrown source location also contains a space, and so the UI test normalization in issue-21763 fails to normalize as expected.

While this new regex does not handle all valid paths, such as those beginning with `\\?\` or `\\name\`, this handles most absolute UNIX and Windows paths. Relative paths don't seem to be applicable.
2026-05-06 22:39:20 +02:00
Jonathan Brouwer b1d22623ab Rollup merge of #156151 - mejrs:non_macro_attr, r=petrochenkov
Don't return dummy MacroData in `get_macro`

I was experimenting with tool attributes and ast manipulation, and wasted some time figuring out that this was happening. AFAIK all users of `get_macro` are expecting an actual macro (and none were reading the dummy MacroData) so there should be no change in behavior.
2026-05-06 22:39:20 +02:00
bjorn3 da6e4d4890 Move CrateInfo computation after codegen_crate
CrateInfo is only necessary during linking and non-local LTO.
2026-05-06 14:51:38 +00:00
bors 365c0e1d7a Auto merge of #155443 - jdonszelmann:canonical, r=lcnr
Improve caching by introducing `TypingMode::ErasedNotCoherence`



r? @lcnr


This introduces `TypingMode::ErasedNotCoherence`. Most typing modes contain a list of opaque types, which are quite often unused during canonicalization. With this change, any time we try canonicalization, we replace whichever typing mode we're currently in with `ErasedNotcoherence`, attempt to canonicalize, and if that fails *retry* in the original typing mode. If erased mode succeeds, this is beneficial because that way the opaque types don't end up in the cache key, allowing more cache reuse.

This seems to have a small (0.5%) slowdown on most programs, but a dramatic (>60%) speedup in specific cases like the rustc-perf `wg-grammar` benchmark. Some more improvements are expected with "eager normalization", which is work that's under way right now.
2026-05-06 13:55:09 +00:00
danieljofficial c5cf60839d add issue links and bless 2026-05-06 14:22:01 +01:00
danieljofficial ccd70c194e move coercion tests out of ui/issues into its folder 2026-05-06 13:41:52 +01:00
mejrs facd03622b Don't return dummy MacroData in get_macro 2026-05-06 14:39:39 +02:00
Waffle Lapkin 278517f345 bless codegen-units tests 2026-05-06 13:57:36 +02:00
Waffle Lapkin af5e1da690 bless mir-opt tests 2026-05-06 13:57:36 +02:00
mu001999 26bfcf3f35 Rename unused_pub_items_in_binary to dead_code_pub_in_binary 2026-05-06 19:34:18 +08:00
mu001999 27a8bb677b Implement unused_pub_items_in_binary lint 2026-05-06 19:34:15 +08:00
Jana Dönszelmann 7ff71be015 Try to canonicalize with erased opaques, retry when opaques are used. 2026-05-06 10:18:21 +02:00
Jana Dönszelmann 814fc17cb6 Deny warnings in rustc crates on stable 2026-05-06 10:13:29 +02:00
Asuna 4fe8268ff9 Refactor Type::size field to TypeId::size method for type_info 2026-05-06 05:41:08 +00:00
Jacob Pratt e826e3f3bf Rollup merge of #156205 - lcnr:move-generalization-test, r=lqd
move generalization test

The forth test of https://github.com/rust-lang/trait-system-refactor-initiative/issues/191#issuecomment-3351555279 isn't actually related to closure signature inference.

closes https://github.com/rust-lang/trait-system-refactor-initiative/issues/191, which has already been fixed by https://github.com/rust-lang/rust/pull/155767

r? types
2026-05-05 22:50:27 -04:00
Jacob Pratt f8a77e26f6 Rollup merge of #156195 - danieljofficial:move-tests-codegen, r=JohnTitor
Move tests codegen

Hi, I have moved some tests into the codegen folder
2026-05-05 22:50:27 -04:00
Jacob Pratt 46b1955d9c Rollup merge of #156170 - inq:add-known-bug-test-144442, r=JohnTitor
add known-bug test for coroutine 'static-yields-non-'static unsoundness (#144442)

Add a `known-bug` regression test for [#144442 ("Unsoundness due to 'static coroutines that yield non-'static values").](https://github.com/rust-lang/rust/issues/144442)

Existing known-bug tests:
```
- tests/ui/closures/static-closures-with-nonstatic-return.rs
- tests/ui/implied-bounds/dyn-erasure-tait.rs
- tests/ui/implied-bounds/dyn-erasure-no-tait.rs
```

Verified in Darwin: running the compiled binary segfaults on current main, so the bug is still present.
2026-05-05 22:50:26 -04:00
Jacob Pratt 7eb0a28679 Rollup merge of #155808 - lapla-cogito:issue_155803, r=oli-obk
Always use `ConstFn` context for `const` closures

fixes rust-lang/rust#155803

Since https://github.com/rust-lang/rust/commit/e8a46117795f82f35e2f4087516a8743e28ba174, `hir_body_const_context()` returned the parent's const context for a `const` closure. But a `const` closure can escape its enclosing body via a `fn`-pointer-typed const item or an opaque return type and be invoked at runtime, so it must be const-checked under the most restrictive `ConstFn` context like a regular `const fn`.

r? oli-obk (since you authored the commit mentioned above, feel free to reroll)
2026-05-05 22:50:23 -04:00
Jacob Pratt b2cc990df0 Rollup merge of #155341 - khyperia:non-type-const, r=BoxyUwU
generic_const_args: allow paths to non type consts

tracking issue: https://github.com/rust-lang/rust/issues/151972

Non type consts should be usable in the type system in `feature(generic_const_args)`. These are directly plugged into the constant evaluator, unlike type consts, which are attempted to be reasoned about by the type system.

Inherent associated constants are not supported at this time, due to complications around how generic arguments are represented for them (it's currently a mess). The mess is being cleaned up (e.g. https://github.com/rust-lang/rust/pull/154758), so instead of trying to hack support in before the refactoring is done, let's just wait to be able to implement it more cleanly.

r? @BoxyUwU
2026-05-05 22:50:18 -04:00
Jacob Pratt 2717d989c9 Rollup merge of #151122 - Jaidenmagnan:main, r=chenyukang
fix: more descriptive error message for enum to integer

Fixes rust-lang/rust#151116
A  more descriptive error message when casting an enum to an Integer. Please review issue linked above.
2026-05-05 22:50:18 -04:00
Jaiden Magnan 0f5d89fea1 fix: CopyPriority addition 2026-05-05 17:34:50 -04:00
Alyssa Haroldsen a8d85e6368 tests/ui: allow spaces in hashbrown src normalization
If one's home directory contains a space, the default location for the
hashbrown source location also contains a space, and so the UI test
normalization in issue-21763 fails to normalize as expected.

While this new regex does not handle all valid paths, such as those
beginning with `\\?\` or `\\name\`, this handles most absolute UNIX and
Windows paths. Relative paths don't seem to be applicable.
2026-05-05 14:23:02 -07:00
lcnr 8634d63321 move test 2026-05-05 22:31:00 +02:00
Jaiden Magnan 61743bf3b0 fix: adding more verbose error message 2026-05-05 16:19:41 -04:00
khyperia cb2c5fc540 generic_const_args: allow paths to non type consts 2026-05-05 17:35:17 +02:00