Commit Graph

8809 Commits

Author SHA1 Message Date
bors
9b0268a43b Auto merge of #141731 - compiler-errors:tweak-fast-path-trait, r=lcnr
Tweak fast path trait handling

(1.) Make it more sound by considering polarity (lol)

(2.) Make it more general, by considering higher-ranked size/copy/clone

(2.) Make it less observable, by only doing copy/clone fast path if there are no regions involved

r? lcnr
2025-06-01 10:59:38 +00:00
Matthias Krüger
387170c74b
Rollup merge of #141740 - nnethercote:hir-ItemKind-field-order, r=fee1-dead
Hir item kind field order

A follow-up to rust-lang/rust#141675.

r? `@fee1-dead`
2025-05-31 18:51:48 +02:00
Matthias Krüger
bace7f986c
Rollup merge of #141703 - compiler-errors:deref-place, r=lcnr
Structurally normalize types as needed in `projection_ty_core`

Introduce a `structurally_normalize` callback to `projection_ty_core`, and then use it before we match on the ty kind in `projection_ty_core`.

Previously we were only structurally normalizing the return type of the `handle_field` struct, but if we were to (e.g.) apply a deref projection to that type, then the resulting type is not guaranteed to be structurally normalized and any subsequent projections applied would ICE.

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/221

I'll leave a few comments inline to explain the changes.

r? lcnr

---

Also fixes rust-lang/rust#141708
2025-05-30 13:39:52 +02:00
Matthias Krüger
ad2d91ce11
Rollup merge of #141507 - RalfJung:atomic-intrinsics, r=bjorn3
atomic_load intrinsic: use const generic parameter for ordering

We have a gazillion intrinsics for the atomics because we encode the ordering into the intrinsic name rather than making it a parameter. This is particularly bad for those operations that take two orderings. Let's fix that!

This PR only converts `load`, to see if there's any feedback that would fundamentally change the strategy we pursue for the const generic intrinsics.

The first two commits are preparation and could be a separate PR if you prefer.

`@BoxyUwU` -- I hope this is a use of const generics that is unlikely to explode? All we need is a const generic of enum type. We could funnel it through an integer if we had to but an enum is obviously nicer...

`@bjorn3` it seems like the cranelift backend entirely ignores the ordering?
2025-05-30 07:01:30 +02:00
Matthias Krüger
896be667b8
Rollup merge of #141407 - mu001999-contrib:dead-code/refactor, r=petrochenkov
Refactor the two-phase check for impls and impl items

Refactor the two-phase dead code check to make the logic clearer and simpler:
1. adding assoc fn and impl into `unsolved_items` directly during the initial construction of the worklist
2. converge the logic of checking whether assoc fn and impl are used to `item_should_be_checked`, and the item is considered used only when its corresponding trait and Self adt are used

This PR only refactors as much as possible to avoid affecting the original functions. However, due to the adjustment of the order of checks, the test results are slightly different, but overall, there is no regression problem

Fixes rust-lang/rust#127911
Fixes rust-lang/rust#128839

Extracted from https://github.com/rust-lang/rust/pull/128637.
r? petrochenkov

try-job: dist-aarch64-linux
2025-05-30 07:01:29 +02:00
Nicholas Nethercote
f8887aa5af Reorder fields in hir::ItemKind variants.
Specifically `TyAlias`, `Enum`, `Struct`, `Union`. So the fields match
the textual order in the source code.

The interesting part of the change is in
`compiler/rustc_hir/src/hir.rs`. The rest is extremely mechanical
refactoring.
2025-05-30 02:23:20 +10:00
Michael Goulet
2a339ce492 Structurally normalize types as needed in projection_ty_core 2025-05-29 11:16:44 +00:00
Michael Goulet
f1da288557 Tweak fast path trait handling 2025-05-29 11:14:36 +00:00
bors
38081f22c2 Auto merge of #141716 - jhpratt:rollup-9bjrzfi, r=jhpratt
Rollup of 16 pull requests

Successful merges:

 - rust-lang/rust#136429 (GCI: At their def site, actually wfcheck the where-clause & always eval free lifetime-generic constants)
 - rust-lang/rust#138139 (Emit warning while outputs is not exe and prints linkage info)
 - rust-lang/rust#141104 (Test(fs): Fix `test_eq_windows_file_type` for Windows 7)
 - rust-lang/rust#141477 (Path::with_extension: show that it adds an extension where one did no…)
 - rust-lang/rust#141533 (clean up old rintf leftovers)
 - rust-lang/rust#141612 (Call out possibility of invariant result in variance markers)
 - rust-lang/rust#141638 (Use `builtin_index` instead of hand-rolling it)
 - rust-lang/rust#141643 (ci: verify that codebuild jobs use ghcr.io)
 - rust-lang/rust#141675 (Reorder `ast::ItemKind::{Struct,Enum,Union}` fields.)
 - rust-lang/rust#141680 (replace TraitRef link memory.md)
 - rust-lang/rust#141682 (interpret/allocation: Fixup type for `alloc_bytes`)
 - rust-lang/rust#141683 (Handle ed2021 precise capturing of unsafe binder)
 - rust-lang/rust#141684 (rustbook: Bump versions of `onig` and `onig_sys`)
 - rust-lang/rust#141687 (core: unstably expose atomic_compare_exchange so stdarch can use it)
 - rust-lang/rust#141690 (Add `rustc_diagnostic_item` to `sys::Mutex` methods)
 - rust-lang/rust#141702 (Add eholk to compiler reviewer rotation)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-29 05:41:04 +00:00
Jacob Pratt
dc22509663
Rollup merge of #141683 - compiler-errors:unsafe-binder-capture, r=oli-obk
Handle ed2021 precise capturing of unsafe binder

Missing pieces from last pr.

r? oli-obk

Fixes https://github.com/rust-lang/rust/issues/141655
2025-05-29 04:49:45 +02:00
Jacob Pratt
e987a99ed2
Rollup merge of #141682 - nia-e:fixup-alloc, r=RalfJung
interpret/allocation: Fixup type for `alloc_bytes`

This can be `FnOnce`, which helps us avoid an extra clone in rust-lang/miri#4343

r? RalfJung
2025-05-29 04:49:45 +02:00
Jacob Pratt
d3c605a051
Rollup merge of #136429 - fmease:gci-fix-def-site-checks, r=BoxyUwU
GCI: At their def site, actually wfcheck the where-clause & always eval free lifetime-generic constants

* 1st commit: Partially addresses [#136204](https://github.com/rust-lang/rust/issues/136204) by turning const eval errors from post to pre-mono for free lifetime-generic constants.
  * As the linked issue/comment states, on master there's a difference between `const _: () = panic!();` (pre-mono error) and `const _<'a>: () = panic!();` (post-mono error) which feels wrong.
  * With this PR, both become pre-mono ones!
* 2nd commit: Oof, yeah, I missed that in the initial impl!

This doesn't fully address #136204 because I still haven't figured out how & where to properly & best suppress const eval of free constants whose predicates don't hold at the def site. The motivating example is `const _UNUSED: () = () where for<'_delay> String: Copy;` which can also be found over at the tracking issue #113521.

r? compiler-errors or reassign
2025-05-29 04:49:39 +02:00
bors
5f025f363d Auto merge of #141581 - lcnr:fold-clauses, r=compiler-errors
add additional `TypeFlags` fast paths

Some crates, e.g. `diesel`, have items with a lot of where-clauses (more than 150). In these cases checking the `TypeFlags` of the whole `param_env` can be very beneficial.

This adds `fn fold_clauses` to mirror the existing `fn visit_clauses` and then uses this in folders which fold `ParamEnv`s.

Split out from rust-lang/rust#141451, depends on rust-lang/rust#141442.

r? `@compiler-errors`
2025-05-29 02:29:01 +00:00
Ralf Jung
a387c86a92 get rid of rustc_codegen_ssa::common::AtomicOrdering 2025-05-28 22:57:55 +02:00
Ralf Jung
4794ea176b atomic_load intrinsic: use const generic parameter for ordering 2025-05-28 22:57:55 +02:00
Michael Goulet
3a736e2726 Handle e2021 precise capturing of unsafe binder 2025-05-28 12:17:18 +00:00
Nia Espera
bcebf58acc
interpret/allocation: make alloc fn be FnOnce 2025-05-28 13:16:20 +02:00
Trevor Gross
e0278ed5af
Rollup merge of #141551 - compiler-errors:hir-lints, r=BoxyUwU
Make two transmute-related MIR lints into HIR lint

Make `PTR_TO_INTEGER_TRANSMUTE_IN_CONSTS` (rust-lang/rust#130540) and `UNNECESSARY_TRANSMUTES` (rust-lang/rust#136083) into "normal" HIR-based lints.

Funny enough this came up in the review of the latter (https://github.com/rust-lang/rust/pull/136083#issuecomment-2614301413), but I guess it just was overlooked.

But anywyas, there's no reason for these to be MIR lints; in fact, it makes the suggestions for them a bit more complicated than necessary.

Note that there's probably a few more simplifications and improvements to be done here. Follow-ups can be done in a separate PR, especially if they're about the messaging and suggestions themselves, which I didn't write.
2025-05-27 20:28:32 -04:00
Matthias Krüger
16af814a4e
Rollup merge of #141495 - compiler-errors:rename-unpack, r=fmease
Rename `{GenericArg,Term}::unpack()` to `kind()`

A well-deserved rename IMO.

r? `@oli-obk` or `@lcnr` (or anyone)

cc `@rust-lang/types,` but I'd be surprised if this is controversial.
2025-05-27 20:57:54 +02:00
León Orell Valerian Liehr
db21caf5ba
Drive-by: Delete dead TyCtxtEnsureOk::const_eval_poly 2025-05-27 18:58:51 +02:00
Mu001999
f83ecd8270 Refactor the two-phase check for impls and impl items 2025-05-27 22:03:21 +08:00
Michael Goulet
5f3ae06db0 Fix some var names 2025-05-27 11:14:47 +00:00
Michael Goulet
29c3babd7c Rename unpack to kind 2025-05-27 11:14:45 +00:00
Michael Goulet
fb4cc991c0
Rollup merge of #141582 - RalfJung:cleanup, r=bjorn3
intrinsics, ScalarInt: minor cleanup

Taken out of https://github.com/rust-lang/rust/pull/141507 while we resolve technical disagreements in that PR.

r? ``@bjorn3``
2025-05-27 13:01:39 +02:00
lcnr
c56efaedfa add additional TypeFlags fast paths 2025-05-26 19:57:48 +00:00
许杰友 Jieyou Xu (Joe)
afb57cadda
Rollup merge of #141513 - nia-e:allocbytes-extend, r=RalfJung
interpret: add allocation parameters to `AllocBytes`

Necessary for a better implementation of [rust-lang/miri#4343](https://github.com/rust-lang/miri/pull/4343). Also included here is the code from that PR, adapted to this new interface for the sake of example and so that CI can run on them; the Miri changes can be reverted and merged separately, though.

r? `@RalfJung`
2025-05-27 01:29:20 +08:00
许杰友 Jieyou Xu (Joe)
9f93c48ddc
Rollup merge of #141433 - compiler-errors:unsafe-binder-captures, r=oli-obk
Properly analyze captures from unsafe binders

We need to represent the unsafe binder unwrap as an adjustment in HIR. Pretty straightforward b/c we already represent it as a projection elem in MIR.

Fixes #141418
Fixes #141417

r? oli-obk
2025-05-27 01:29:18 +08:00
Nia Espera
e388a3e405
extend allocbytes with associated type 2025-05-26 00:15:16 +02:00
Michael Goulet
a8ae2af967 hir_body_const_context should take LocalDefId 2025-05-25 15:57:24 +00:00
Guillaume Gomez
7cd749deff
Rollup merge of #141511 - Noratrieb:codegen-fn-attrs, r=compiler-errors
Cleanup CodegenFnAttrFlags

- Rename `USED` to `USED_COMPILER` to better reflect its behavior.
- Reorder some items to group the used and allocator flags together
- Renumber them without gaps
2025-05-24 21:23:50 +02:00
Noratrieb
fa2bb599bc Cleanup CodegenFnAttrFlags
- Rename `USED` to `USED_COMPILER` to better reflect its behavior.
- Reorder some items to group the used and allocator flags together
- Renumber them without gaps
2025-05-24 20:31:37 +02:00
Ralf Jung
ff3341434d ScalarInt: support conversion with signed int types and cmp::Ordering 2025-05-24 16:13:10 +02:00
lcnr
326b7e9a6b yeet CanonicalVarInfo 2025-05-23 12:10:53 +00:00
Michael Goulet
04ddafc53c Properly analyze captures from unsafe binders 2025-05-23 10:43:13 +00:00
bors
52bf0cf795 Auto merge of #140553 - BoxyUwU:defer_type_system_ctfe, r=compiler-errors
Defer evaluating type system constants when they use infers or params

Split out of #137972, the parts necessary for associated const equality and min generic const args to make progress and have correct semantics around when CTFE is invoked. According to a [previous perf run](https://perf.rust-lang.org/compare.html?start=93257e2d20809d82d1bc0fcc1942480d1a66d7cd&end=01b4cbf0f47c3f782330db88fa5ba199bba1f8a2&stat=instructions:u) of adding the new `const_arg_kind` query we should expect minor regressions here.

I think this is acceptable as we should be able to remove this query relatively soon once mgca is more complete as we'll then be able to implement GCE in terms of mgca and rip out `GCEConst` at which point it's trivial to determine what kind of anon const we're dealing with (either it has generics and is a repeat expr hack, or it doesnt and is a normal anon const).

This should only affect unstable code as we handle repeat exprs specially and those are the only kinds of type system consts that are allowed to make use of generic parameters.

Fixes #133066
Fixes #133199
Fixes #136894
Fixes #137813

r? compiler-errors
2025-05-23 05:30:45 +00:00
bors
912981a9ea Auto merge of #141396 - matthiaskrgr:rollup-feg050g, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #135562 (Add ignore value suggestion in closure body)
 - #139635 (Finalize repeat expr inference behaviour with inferred repeat counts)
 - #139668 (Handle regions equivalent to 'static in non_local_bounds)
 - #140218 (HIR ty lowering: Clean up & refactor the lowering of type-relative paths)
 - #140435 (use uX::from instead of _ as uX in non - const contexts)
 - #141130 (rustc_on_unimplemented cleanups)
 - #141286 (Querify `coroutine_hidden_types`)

Failed merges:

 - #140247 (Don't build `ParamEnv` and do trait solving in `ItemCtxt`s when lowering IATs)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-22 21:02:18 +00:00
Boxy
217c4ad427 Review Comments 2025-05-22 12:47:19 +01:00
bors
d423c815a6 Auto merge of #141135 - compiler-errors:fast-path-2, r=lcnr
Fast path for processing some obligations in the new solver

Fast path applies to:
- Dyn compatibility predicates
- Region and type outlives predicates
- Trivially sized predicates
2025-05-22 11:39:10 +00:00
Boxy
996a185ba7 Introduce tcx.anon_const_kind query 2025-05-21 20:20:19 +01:00
Michael Goulet
6555ef7f09 Querify coroutine_hidden_types 2025-05-20 11:50:25 +00:00
Stuart Cook
599b08ada8
Rollup merge of #140874 - mejrs:rads, r=WaffleLapkin
make `rustc_attr_parsing` less dominant in the rustc crate graph

It has/had a glob re-export of `rustc_attr_data_structures`, which is a crate much lower in the graph, and a lot of crates were using it *just* (or *mostly*) for that re-export, while they can rely on `rustc_attr_data_structures` directly.

Previous graph:
![graph_1](https://github.com/user-attachments/assets/f4a5f13c-4222-4903-b56d-28c83511fcbd)

Graph with this PR:
![graph_2](https://github.com/user-attachments/assets/1e053d9c-75cc-402b-84df-86229c98277a)

The first commit keeps the re-export, and just changes the dependency if possible. The second commit is the "breaking change" which removes the re-export, and "explicitly" adds the `rustc_attr_data_structures` dependency where needed. It also switches over some src/tools/*.

The second commit is actually a lot more involved than I expected. Please let me know if it's a better idea to back it out and just keep the first commit.
2025-05-19 13:24:54 +10:00
León Orell Valerian Liehr
3af0c43f06
Rollup merge of #140926 - azhogin:azhogin/async-drop-coroutine-layout-returns-layout-error, r=oli-obk
Return value of coroutine_layout fn changed to Result with LayoutError

Continue of https://github.com/rust-lang/rust/pull/140902:
`coroutine_layout` fn is now returns `Result` with `LayoutError` to have consistent error with `layout_of_uncached`.
`async_drop_coroutine_layout` fn is now return `LayoutError::TooGeneric` in case of not-fully-specialized `async_drop_in_place<T>::{closure}` coroutine.
2025-05-18 18:44:12 +02:00
mejrs
178e09ed37 Remove rustc_attr_data_structures re-export from rustc_attr_parsing 2025-05-18 18:14:43 +02:00
Michael Goulet
407fac5479 Fast path for sized pred 2025-05-18 12:18:44 +00:00
bors
16244bc37a Auto merge of #140856 - oli-obk:merge-queries2, r=nnethercote
Merge mir query analysis invocations

r? `@ghost`

same thing as https://github.com/rust-lang/rust/pull/140854 just a different set of queries

Doing this in general has some bad cache coherence issues because the query caches are laid out in Vec<QueryResult> lists per query where each index refers to a DefId in the same order as we're iterating. Iterating two or more lists at the same time does have cache issues, so I want to poke a bit at it to see if we can't merge just a few of them at a time.
2025-05-17 22:31:43 +00:00
bors
a43b8d1d2b Auto merge of #141113 - matthiaskrgr:rollup-k7izuh8, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #140208 (Make well-formedness predicates no longer coinductive)
 - #140957 (Add `#[must_use]` to Array::map)
 - #141031 (Async drop fix for dropee from another crate (#140858))
 - #141036 (ci: split the dist-ohos job)
 - #141051 (Remove some unnecessary erases)
 - #141056 (Lowercase git url for rust-lang/enzyme.git)
 - #141059 (HIR: explain in comment why `ExprKind::If` "then" is an `Expr`)
 - #141070 (Do not emit help when shorthand from macro when suggest `?` or `expect`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-17 10:13:08 +00:00
Matthias Krüger
8e30998c18
Rollup merge of #141051 - compiler-errors:less-erase, r=nnethercote
Remove some unnecessary erases

Some nits I pulled out of https://github.com/rust-lang/rust/pull/140814.
2025-05-17 10:33:10 +02:00
Matthias Krüger
04bc9d13ca
Rollup merge of #141031 - azhogin:azhogin/async-drop-dependency-fix, r=oli-obk
Async drop fix for dropee from another crate (#140858)

Fixes https://github.com/rust-lang/rust/issues/140858.

For `AsyncDestructor` impl def id was wrongly kept as a LocalDefId, which causes crash when dropee is declared in another crate.

Also, potential problem found:
when user crate drops type with async drop in dependency crate, and user crate doesn't enable `feature(async_drop)`, then sync drop version will be used.

Is it a problem? Do we need some notification about such situations?
2025-05-17 10:33:09 +02:00
bors
b0e925903a Auto merge of #141024 - jieyouxu:revert-arm64ec, r=wesleywiser
Revert "Fix linking statics on Arm64EC #140176"

This reverts PR #140176.
Unfortunately, this will reopen https://github.com/rust-lang/rust/issues/138541 (re-breaking the `arm64ec-pc-windows-msvc` target).

Unfortunately, multiple people are [reporting linker warnings related to `__rust_no_alloc_shim_is_unstable`](https://github.com/rust-lang/rust/pull/140176#issuecomment-2879715554) after this change in `x86_64-pc-windows-msvc` as well. The solution isn't quite clear yet, let's revert to avoid the linker warnings on the Tier 1 MSVC target for now[^timing], and try a reland with a determined solution for `__rust_no_alloc_shim_is_unstable`.

Judging from [people reporting that they are observing this also when bootstrapping w/ stage0 rustc](https://github.com/rust-lang/rust/pull/140176#issuecomment-2881867433), we may have to cut a new beta and then repoint stage0 against that newer beta?

cc `@dpaoliello` `@wesleywiser`

r? `@wesleywiser` (or compiler)

[^timing]: Note that it's still RustWeek this week, so most team members are N/A.
2025-05-17 07:00:46 +00:00
Andrew Zhogin
7b2dcf2989 Async drop fix for dropee from another crate (#140858) 2025-05-15 20:05:07 +07:00