9361 Commits

Author SHA1 Message Date
ash
fa7e474f9c remove FIXME from has_significant_drop, replaced with checking non_region_infer 2025-09-15 13:55:20 -06:00
Jo Bates
1ebf69d1b1 initial implementation of the darwin_objc unstable feature 2025-09-13 16:06:22 -07:00
Cameron Steffen
b995a55caf Don't store defaultness for inherent impl items 2025-09-12 15:14:15 -05:00
Cameron Steffen
9615ec7d10 Split AssocContainer::{InherentImpl,TraitImpl} 2025-09-12 15:14:15 -05:00
Cameron Steffen
88a8bfcaf0 Introduce hir::ImplItemImplKind 2025-09-12 15:14:15 -05:00
Cameron Steffen
5590e55b03 Rename AssocItemContainer -> AssocContainer 2025-09-12 15:10:30 -05:00
Cameron Steffen
16c218c57f Introduce trait_item_of 2025-09-12 15:10:30 -05:00
bors
a171994070 Auto merge of #146329 - lcnr:opaque-type-infer-alias-candidates, r=BoxyUwU
consider item bounds for non-yet-defined opaque types

Based on rust-lang/rust#140405.

fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/182
fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/196
fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/205

there's some jank here, see https://github.com/rust-lang/trait-system-refactor-initiative/issues/229

## Design

If the self type is an inference variable which has been sub-unified with am opaque type, we need to incompletely guide inference to avoid breakage.

In this case, we
- look at the item bounds of all sub-unified opaque types, and
- blanket impls which do not constrain the self type

Even if there are applicable candidates, we always force their certainty to be `Maybe`, so they will always have to be reproven once we've constrained the inference variable.

This is a bit iffy, see the added tests.

r? `@BoxyUwU`
2025-09-12 14:28:42 +00:00
bors
8e2ed71eff Auto merge of #146328 - zetanumbers:fix-141951, r=lcnr
Skip typeck for items w/o their own typeck context

Skip items which forward typeck to their ancestor.

Should remove some potential but unnecessary typeck query waits, hence might improve performance for the parallel frontend.

Thanks to `@ywxt` for a fix suggestion

Fixes rust-lang/rust#141951
2025-09-12 03:51:54 +00:00
Michael Goulet
cf224ea1fb incompletely prefer opaque type bounds when self type bottoms out in infer 2025-09-11 12:13:03 +02:00
Folkert de Vries
01e83adc88 c-variadic: allow trait methods to be c-variadic
but a C-variadic method makes a trait dyn-incompatible. That is because
methods from dyn traits, when cast to a function pointer, create a shim.
That shim can't really forward the c-variadic arguments.
2025-09-11 10:27:28 +02:00
Ralf Jung
72225060ed clarify current MIR semantics re: overlapping assignment
and double-check that we match it in codegen
2025-09-10 15:59:11 +02:00
Matthias Krüger
212baec446 Rollup merge of #146391 - beepster4096:trimnt, r=saethlin
Trim paths less in MIR dumping

With this PR, the paths MIR dump filters and that are printed at the start of a dump file are no longer trimmed. They don't include the crate that is being compiled, however.
2025-09-10 14:17:40 +02:00
Matthias Krüger
422c76adae Rollup merge of #146178 - folkertdev:static-align, r=jdonszelmann,ralfjung,traviscross
Implement `#[rustc_align_static(N)]` on `static`s

Tracking issue: https://github.com/rust-lang/rust/issues/146177

```rust
#![feature(static_align)]

#[rustc_align_static(64)]
static SO_ALIGNED: u64 = 0;
```

We need a different attribute than `rustc_align` because unstable attributes are tied to their feature (we can't have two unstable features use the same unstable attribute). Otherwise this uses all of the same infrastructure as `#[rustc_align]`.

r? `@traviscross`
2025-09-10 14:17:38 +02:00
Ralf Jung
7abbc9c8b2 avoid calling insert_presorted more than once 2025-09-10 08:40:12 +02:00
Ralf Jung
64ea775d27 interpret: copy_provenance: avoid large intermediate buffer for large repeat counts 2025-09-10 08:40:12 +02:00
beepster4096
90e74de473 don't trim paths in mir dumping when filtering and at the top of the file 2025-09-09 16:23:14 -07:00
Folkert de Vries
cbacd00f10 allow #[rustc_align_static(N)] on statics
We need a different attribute than `rustc_align` because unstable attributes are
tied to their feature (we can't have two unstable features use the same
unstable attribute). Otherwise this uses all of the same infrastructure
as `#[rustc_align]`.
2025-09-09 21:54:54 +02:00
bors
364da5d88d Auto merge of #145717 - BoxyUwU:erase_regions_rename, r=lcnr
rename erase_regions to erase_and_anonymize_regions

I find it consistently confusing that `erase_regions` does more than replacing regions with `'erased`. it also makes some code look real goofy to be writing manual folders to erase regions with a comment saying "we cant use erase regions" :> or code that re-calls erase_regions on types with regions already erased just to anonymize all the bound regions.

r? lcnr

idk how i feel about the name being almost twice as long now
2025-09-09 15:04:44 +00:00
Boxy
332d8d6235 Driveby fixes 2025-09-09 14:49:16 +02:00
Boxy
e379c77586 erase_regions to erase_and_anonymize_regions 2025-09-09 14:49:16 +02:00
Stuart Cook
915f9ff160 Rollup merge of #146324 - RalfJung:no-ptr-fragment, r=oli-obk
const-eval: disable pointer fragment support

This fixes https://github.com/rust-lang/rust/issues/146291 by disabling pointer fragment support for const-eval. I want to properly fix this eventually, but won't get to it in the next few weeks, so this is an emergency patch to prevent the buggy implementation from landing on stable. The beta cutoff is on Sep 12th so if this PR lands after that, we'll need a backport.
2025-09-09 14:35:05 +10:00
Stuart Cook
33318ed207 Rollup merge of #145819 - jdonszelmann:convert-limits, r=fmease
Port limit attributes to the new attribute parsing infrastructure

Doesn't pass tests, to be rebased on https://github.com/rust-lang/rust/pull/145792 which will solve that

r? `@fmease`
2025-09-09 14:35:01 +10:00
Jana Dönszelmann
6087d89004 fixup limit handling code 2025-09-08 15:07:12 -07:00
bors
9c27f27ea3 Auto merge of #140375 - lcnr:subrelations-infcx, r=BoxyUwU
eagerly compute `sub_unification_table` again

Previously called `sub_relations`. We still only using them for diagnostics right now. This mostly reverts rust-lang/rust#119989. Necessary for type inference guidance due to not-yet defined opaque types, cc https://github.com/rust-lang/trait-system-refactor-initiative/issues/182.

We could use them for cycle detection in generalization and it seems desirable to do so in the future. However, this is unsound with the old trait solver as its cache does not track these `sub_unification_table` in any way.

We now properly track the `sub_unification_table` when canonicalizing so using them in the new solver is totally sound and the performance impact is far more manageable than I thought back in rust-lang/rust#119989.

r? `@compiler-errors`
2025-09-08 19:39:36 +00:00
Matthias Krüger
2eab500413 Rollup merge of #146313 - nnethercote:rustc_middle-ty-cleanups-2, r=lcnr
Some `rustc_middle` cleanups

Minor improvements I found while looking through this code.

r? `@BoxyUwU`
2025-09-08 16:34:58 +02:00
Matthias Krüger
1e46fa94a3 Rollup merge of #146111 - ChayimFriedman2:more-ns-specific-defid, r=lcnr
Migrate more things in the new solver to specific `DefId`s

Continuation of https://github.com/rust-lang/rust/pull/145377. I migrated the rest of the types, except aliases.

Aliases are problematic because opaques and associated types share the same type in the new solver. `@jackh726,` `@lcnr,` `@ShoyuVanilla` I'd like to hear ideas here. Anyway, even if we do nothing with them we already got a substantial improvement.

r? types
2025-09-08 16:34:55 +02:00
lcnr
2cb04b960f inline CanonicalTyVarKind 2025-09-08 14:17:56 +02:00
Daria Sukhonina
78718d5570 Skip typeck for items w/o their own typeck context
More details on about this fix:

https://rust-lang.zulipchat.com/#narrow/channel/187679-t-compiler.2Fparallel-rustc/topic/ICE.3A.20typecks.20AnonConst.20under.20parallel.20rustc.28.23141951.29/with/538200980

Co-authored-by: ywxt <ywxtcwh@gmail.com>
2025-09-08 14:50:23 +03:00
Ralf Jung
aed0ed4c93 const-eval: disable pointer fragment support 2025-09-08 13:22:52 +02:00
Nicholas Nethercote
a171ec3cf0 Move describe_as_module from rustc_middle::print to rustc:middle::query.
That way it doesn't need to be exported.
2025-09-08 06:34:39 +10:00
Nicholas Nethercote
1e679154da Move rustc_middle::MaxUniverse to rustc_infer.
Because `rust_infer` is the only crate that uses it.
2025-09-08 06:34:32 +10:00
Nicholas Nethercote
006c85d017 Make some matches non-exhaustive.
Exhaustive match isn't necessary for these trivial cases, and some
similar nearby methods are non-exhaustive.
2025-09-08 06:31:59 +10:00
Matthias Krüger
36557d1046 Rollup merge of #146297 - cjgillot:may-observe-address, r=saethlin
Introduce PlaceContext::may_observe_address.

A small utility method to avoid open-coding the logic in several MIR opts.
2025-09-07 20:02:29 +02:00
Camille GILLOT
4e7a068c9a Introduce PlaceContext::may_observe_address. 2025-09-07 13:51:53 +00:00
Marijn Schouten
ad21f439dc rustc_middle: clippy fixes 2025-09-05 17:44:53 +00:00
Jacob Pratt
b4f76b3de8 Rollup merge of #146182 - ChayimFriedman2:ns-probe, r=jackh726
Don't require next-solver `ProbeRef` to be `Copy`

rust-analyzer would like to use a non-interned `Probe` there.

Also rename it to `Probe` for this reason.

We can make it `Copy` (although then `Probe` will need to be `Clone` for rust-analyzer) but it seems just non-needed.

r? types
2025-09-04 01:43:22 -04:00
Stuart Cook
f90cc353b8 Rollup merge of #145932 - JamieCunliffe:target-feature-inlining, r=jackh726
Allow `inline(always)` with a target feature behind a unstable feature `target_feature_inline_always`.

Rather than adding the inline always attribute to the function definition, we add it to the callsite. We can then check that the target features match and that the call would be safe to inline. If the function isn't inlined due to a mismatch, we emit a warning informing the user that the function can't be inlined due to the target feature mismatch.

See tracking issue rust-lang/rust#145574
2025-09-04 10:01:55 +10:00
Stuart Cook
cd59ee791f Rollup merge of #145342 - dianne:if-let-super-let, r=nnethercote
fix drop scope for `super let` bindings within `if let`

Fixes rust-lang/rust#145328 by making non-lifetime-extended `super let` reuse the logic used to compute drop scopes for non-lifetime-extended temporaries.

Also fixes rust-lang/rust#145374, which regressed due to rust-lang/rust#143376 introducing `if let`-like scopes for match arms with guards.

Tracking issue for `super let`: rust-lang/rust#139076

This is a regression fix / breaking change for macros stably exposing `super let`, including `pin!` and `format_args!`.
Nominating to be discussed alongside rust-lang/rust#145328: ```@rustbot``` label +I-lang-nominated +I-libs-api-nominated
2025-09-04 10:01:53 +10:00
Chayim Refael Friedman
5d13845e5b Don't require next-solver ProbeRef to be Copy
rust-analyzer would like to use a non-interned `Probe` there.

Also rename it to `Probe` for this reason.
2025-09-04 02:09:59 +03:00
bors
94722cabf4 Auto merge of #146125 - GuillaumeGomez:rollup-ld81n7e, r=GuillaumeGomez
Rollup of 14 pull requests

Successful merges:

 - rust-lang/rust#144066 (stabilize c-style varargs for sysv64, win64, efiapi, aapcs)
 - rust-lang/rust#145783 (add span to struct pattern rest (..))
 - rust-lang/rust#146034 (Update target spec metadata of Arm64EC Windows and Trusty targets)
 - rust-lang/rust#146064 (Add compiler error when trying to use concat metavar expr in repetitions)
 - rust-lang/rust#146070 (rustdoc-search: skip loading unneeded fnData)
 - rust-lang/rust#146088 (constify impl Try for ControlFlow)
 - rust-lang/rust#146089 (fix a constness ordering bug in rustfmt)
 - rust-lang/rust#146091 (fix rustdoc `render_call_locations`  panicking because of default span `DUMMY_SP` pointing at non local-source file)
 - rust-lang/rust#146094 (Make `Parser::parse_for_head` public for rustfmt usage)
 - rust-lang/rust#146102 (Remove dead code stemming from an old effects desugaring)
 - rust-lang/rust#146115 (Add maintainer for VxWorks)
 - rust-lang/rust#146116 (Adjust issue-118306.rs test after LLVM change)
 - rust-lang/rust#146117 (Fix search index generation)
 - rust-lang/rust#146118 (improve process::abort rendering in Miri backtraces)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-09-02 16:19:45 +00:00
Guillaume Gomez
07f7d86f36 Rollup merge of #146102 - fmease:rm-dead-eff-code-iii, r=fee1-dead
Remove dead code stemming from an old effects desugaring

CC https://github.com/rust-lang/rust/pull/132374, https://github.com/rust-lang/rust/pull/133443.

r? fee1-dead
2025-09-02 17:08:58 +02:00
bors
a2c8b0b92c Auto merge of #145951 - lcnr:proof-tree-as-query, r=compiler-errors
cleanup and cache proof tree building

There's some cruft left over from when we had deep proof trees. We never encounter overflow when evaluating proof trees. Even if the recursion limit is `0`, we still only hit the overflow limit when evaluating nested goals of the root. The root goal simply inherits the `root_depth` of the `SearchGraph`.

Split `evaluate_root_goal_for_proof_tree` from the rest of the trait solver. This enables us to simplify the implementation of `evaluate_goal_raw` and the `ProofTreeBuilder` as we no longer need to manually track the state of the builder and can instead use separate types for that. It does require making a few internal methods into associated functions taking a `delegate` and a `span` instead of the `EvalCtxt` itself.

I've also split `SearchGraph::evaluate_goal` and `SearchGraph::evaluate_root_goal_for_proof_tree` for the same reason. Both functions don't actually share too much code, so by splitting them each version gets significantly easier to read.

Add a `query evaluate_root_goal_for_proof_tree_raw` to cache proof tree building. This requires arena allocating `inspect::Probe`. I've added a new type alias `I::ProbeRef` for this. We may need to adapt this for rust-analyzer? It would definitely be easy to remove the `Copy` bound here 🤔
2025-09-02 13:13:17 +00:00
Chayim Refael Friedman
6f0ebdb71a Migrate more things in the new solver to specific DefIds 2025-09-02 11:35:25 +03:00
bors
75ee9ffd5e Auto merge of #145925 - lcnr:revealing-use-closures-2, r=BoxyUwU
`-Znext-solver`: support non-defining uses in closures

Cleaned up version of rust-lang/rust#139587, finishing the implementation of https://github.com/rust-lang/types-team/issues/129. This does not affect stable. The reasoning for why this is the case is subtle however.

## What does it do

We split `do_mir_borrowck` into `borrowck_collect_region_constraints` and `borrowck_check_region_constraints`, where `borrowck_collect_region_constraints` returns an enormous `CollectRegionConstraintsResult` struct which contains all the relevant data to actually handle opaque type uses and to check the region constraints later on.

`query mir_borrowck` now simply calls `BorrowCheckRootCtxt::do_mir_borrowck` which starts by iterating over all nested bodies of the current function - visiting nested bodies before their parents - and computing their `CollectRegionConstraintsResult`.

After we've collected all constraints it's time to actually compute the concrete types for the opaques defined by this function. With this PR we now compute the concrete types of opaques for each body before using them to check the non-defining uses of any of them.

After we've computed the concrete types by using all bodies, we use `apply_computed_concrete_opaque_types` for each body to constrain non-defining uses, before finally finishing with `borrowck_check_region_constraints`. We always visit nested bodies before their parents when doing this.

## `ClosureRegionRequirements`

As we only call `borrowck_collect_region_constraints` for nested bodies before type checking the parent, we can't simply use the final `ClosureRegionRequirements` of the nested body during MIR type check. We instead track that we need to apply these requirements in `deferred_closure_requirements`.

We now manually apply the final closure requirements to each body after handling opaque types.

This works, except that we may need the region constraints of nested bodies to successfully define an opaque type in the parent. This is handled by using a new `fn compute_closure_requirements_modulo_opaques` which duplicates region checking - while ignoring any errors - before we've added the constraints from `apply_computed_concrete_opaque_types`. This is necessary for a lot of async tests, as pretty much the entire function is inside of an async block while the opaque type gets defined in the parent.

As an performance optimization we only use `fn compute_closure_requirements_modulo_opaques` in case the nested body actually depends on any opaque types. Otherwise we eagerly call `borrowck_check_region_constraints` and apply the final closure region requirements right away.

## Impact on stable code

Handling the opaque type uses in the parent function now only uses the closure requirements *modulo opaques*, while it previously also considered member constraints from nested bodies. `External` regions are never valid choice regions. Also, member constraints will never constrain a member region if it is required to be outlived by an external region, as that fails the upper-bound check. 564ee21912/compiler/rustc_borrowck/src/region_infer/opaque_types/member_constraints.rs (L90-L96)

Member constraints therefore never add constraints for external regions :>

r? `@BoxyUwU`
2025-09-01 20:56:46 +00:00
León Orell Valerian Liehr
6fc0cf4288 Remove dead code stemming from an old effects desugaring 2025-09-01 21:39:01 +02:00
Stuart Cook
142ad69698 Rollup merge of #146042 - estebank:issue-83413, r=lcnr
Detect negative literal inferred to unsigned integer

```
error[E0277]: the trait bound `usize: Neg` is not satisfied
  --> $DIR/negative-literal-infered-to-unsigned.rs:2:14
   |
LL |     for x in -5..5 {
   |              ^^ the trait `Neg` is not implemented for `usize`
   |
help: consider specifying an integer type that can be negative
   |
LL |     for x in -5isize..5 {
   |                +++++
```

Applying this suggestion will always end up in another E0308 error at the point where the unsigned inference comes from, which should help with understanding what the actual problem is.

Fix rust-lang/rust#83413.
2025-09-01 12:42:26 +10:00
Nicholas Nethercote
5ce3797073 Introduce MirDumper and MirWriter.
MIR dumping is a mess. There are lots of functions and entry points,
e.g. `dump_mir`, `dump_mir_with_options`, `dump_polonius_mir`,
`dump_mir_to_writer`. Also, it's crucial that `create_dump_file` is
never called without `dump_enabled` first being checked, but there is no
mechanism for ensuring this and it's hard to tell if it is satisfied on
all paths. (`dump_enabled` is checked twice on some paths, however!)

This commit introduces `MirWriter`, which controls the MIR writing, and
encapsulates the `extra_data` closure and `options`. Two existing
functions are now methods of this type. It sets reasonable defaults,
allowing the removal of many `|_, _| Ok(())` closures.

The commit also introduces `MirDumper`, which is layered on top of
`MirWriter`, and which manages the creation of the dump files,
encapsulating pass names, disambiguators, etc. Four existing functions
are now methods of this type.
- `MirDumper::new` will only succeed if dumps are enabled, and will
  return `None` otherwise, which makes it impossible to dump when you
  shouldn't.
- It also sets reasonable defaults for various things like
  disambiguators, which means you no longer need to specify them in many
  cases. When they do need to be specified, it's now done via setter
  methods.
- It avoids some repetition. E.g. `dump_nll_mir` previously specifed the
  pass name `"nll"` four times and the disambiguator `&0` three times;
  now it specifies them just once, to put them in the `MirDumper`.
- For Polonius, the `extra_data` closure can now be specified earlier,
  which avoids having to pass some arguments through some functions.
2025-09-01 09:19:03 +10:00
Nicholas Nethercote
2d21c13405 Indent some functions.
This commit exists purely to simplify reviewing: these functions will
become methods in the next commit. This commit indents them so that the
next commit is more readable.
2025-09-01 08:52:34 +10:00
Nicholas Nethercote
d3e2c93498 Use trait object references for closures.
The dynamic dispatch cost doesn't matter for MIR dumping, which is
perf-insensitive. And it's necessary for the next commit, which will
store some `extra_data` closures in a struct.
2025-09-01 08:52:34 +10:00