1132 Commits

Author SHA1 Message Date
Tomasz Miąsko
2a03a948b9 Deduce captures(none) for a return place and parameters
Extend attribute deduction to determine whether parameters using
indirect pass mode might have their address captured. Similarly to
the deduction of `readonly` attribute this information facilitates
memcpy optimizations.
2025-10-25 22:53:52 +02:00
Oli Scherer
ad4bd083f3 Add not-null pointer patterns to pattern types 2025-10-21 11:22:51 +00:00
Oli Scherer
d9f22d289c Pattern types have their base type as a field 2025-10-21 10:37:07 +00:00
bors
0c0f27afd4 Auto merge of #147695 - cjgillot:deduce-param-freeze, r=tmiasko
deduced_param_attrs: check Freeze on monomorphic types.

`deduced_param_attrs` currently checks `Freeze` bound on polymorphic MIR. This pessimizes the deduction, as generic types are not `Freeze` by default.

This moves the check to the ABI adjustment.
2025-10-18 12:37:45 +00:00
Camille Gillot
97f88f5603 Generalize the non-freeze and needs_drop handling. 2025-10-17 16:28:37 +00:00
Cameron Steffen
e60e9f0826 Split impl_(opt_)trait_ref 2025-10-17 08:36:34 -05:00
Cameron Steffen
ca5073759c Remove some impl_trait_ref usages 2025-10-17 08:36:34 -05:00
Cameron Steffen
c17b2dc283 Split trait_id_of_impl into impl(_opt)_trait_id 2025-10-17 08:36:34 -05:00
Camille Gillot
031929c369 deduced_param_attrs: check Freeze on monomorphic types. 2025-10-15 21:21:05 +00:00
Boxy Uwu
8e9b0c4ca9 rename select_where_possible and select_all_or_error 2025-10-07 23:02:23 +01:00
Kivooeo
67bc030833 change flt back to ftl 2025-10-04 18:18:58 +00:00
bors
4b9c62b4da Auto merge of #147138 - jackh726:split-canonical-bound, r=lcnr
Split Bound index into Canonical and Bound

See [#t-types/trait-system-refactor > perf `async-closures/post-mono-higher-ranked-hang.rs`](https://rust-lang.zulipchat.com/#narrow/channel/364551-t-types.2Ftrait-system-refactor/topic/perf.20.60async-closures.2Fpost-mono-higher-ranked-hang.2Ers.60/with/541535613) for context

Things compile and tests pass, but not sure if this actually solves the perf issue (edit: it does). Opening up this to do a perf (and maybe crater) run.

r? lcnr
2025-10-02 08:09:33 +00:00
jackh726
d1bbd39c59 Split Bound into Canonical and Bound 2025-09-30 12:58:28 -04:00
Jubilee Young
0c9d0dfe04 remove explicit deref of AbiAlign for most methods
Much of the compiler calls functions on Align projected from AbiAlign.
AbiAlign impls Deref to its inner Align, so we can simplify these away.
Also, it will minimize disruption when AbiAlign is removed.

For now, preserve usages that might resolve to PartialOrd or PartialEq,
as those have odd inference.
2025-09-28 15:02:14 -07:00
Stuart Cook
fab06469ee Rollup merge of #146667 - calebzulawski:simd-mono-lane-limit, r=lcnr,RalfJung
Add an attribute to check the number of lanes in a SIMD vector after monomorphization

Allows std::simd to drop the `LaneCount<N>: SupportedLaneCount` trait and maintain good error messages.

Also, extends rust-lang/rust#145967 by including spans in layout errors for all ADTs.

r? ``@RalfJung``

cc ``@workingjubilee`` ``@programmerjake``
2025-09-25 20:31:53 +10:00
Caleb Zulawski
f5c6c9542e Add an attribute to check the number of lanes in a SIMD vector after monomorphization
Unify zero-length and oversized SIMD errors
2025-09-23 20:47:34 -04:00
Matthias Krüger
b7ab58eb4d Rollup merge of #146597 - modhanami:add-struct-tail-recursion-limit-span, r=oli-obk
Add span for struct tail recursion limit error

Fixes rust-lang/rust#135629

Changes
1. Add span to RecursionLimitReached
2. Add ObligationCause parameter to struct_tail_raw
4. Update call sites to pass nearby ObligationCause or create one
5. Update affected .stderr
2025-09-18 17:20:57 +02:00
León Orell Valerian Liehr
26f3337d4e Remove DynKind 2025-09-17 04:46:46 +02:00
Tawan Muadmuenwai
6912631d3e Add span for struct tail recursion limit error 2025-09-16 23:04:59 +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
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
e379c77586 erase_regions to erase_and_anonymize_regions 2025-09-09 14:49:16 +02:00
Jana Dönszelmann
6087d89004 fixup limit handling code 2025-09-08 15:07:12 -07:00
Nicholas Nethercote
301655eafe Revert introduction of [workspace.dependencies].
This was done in #145740 and #145947. It is causing problems for people
using r-a on anything that uses the rustc-dev rustup package, e.g. Miri,
clippy.

This repository has lots of submodules and subtrees and various
different projects are carved out of pieces of it. It seems like
`[workspace.dependencies]` will just be more trouble than it's worth.
2025-09-02 19:12:54 +10: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
lcnr
a3993c5416 change order of nested_bodies_within 2025-08-27 14:11:07 +02:00
Nicholas Nethercote
200f56d605 Add itertools to [workspace.dependencies]. 2025-08-27 14:21:21 +10:00
Nicholas Nethercote
c50d2cc807 Add tracing to [workspace.dependencies]. 2025-08-27 14:21:19 +10:00
Nikita Popov
d71ed8d19b Tell LLVM about read-only captures
`&Freeze` parameters are not only `readonly` within the function,
but any captures of the pointer can also only be used for reads.
This can now be encoded using the `captures(address, read_provenance)`
attribute.
2025-08-20 19:08:16 +02:00
Cameron Steffen
bf266dc834 Propagate TraitImplHeader to hir 2025-08-11 17:05:42 -05:00
Stuart Cook
b30fe4bb8b Rollup merge of #145147 - fee1-dead-contrib:push-mxxpmlpmzmsz, r=compiler-errors
rename `TraitRef::from_method` to `from_assoc`

also add a note to `GenericArgs::truncate_to`
2025-08-10 19:45:53 +10:00
Deadbeef
2736d66a1f rename TraitRef::from_method to from_assoc
also add a note to `GenericArgs::truncate_to`
2025-08-09 14:22:01 +08:00
bjorn3
7d88f657e9 Fix ICE 2025-08-06 18:31:58 +00:00
bjorn3
e2acc6c5f4 Avoid using unadjusted ABI for the thread-local shim
This restricts the uses of the unadjusted ABI to LLVM intrinsics. The
Rust ABI works fine for the thread-local shim as it always returns
pointers directly like the backend expects.
2025-08-06 16:05:30 +00:00
bjorn3
b0619327ef Change adjust_for_rust_scalar into arg_attrs_for_rust_scalar
Directly creating the ArgAttributes rather than adjusting one is a bit
clearer.
2025-08-06 16:05:30 +00:00
Michael Goulet
d05bb98d6b Extract borrowck coroutine drop-liveness hack 2025-07-31 17:38:28 +00:00
Cameron Steffen
172af038a7 Rename trait_of_item -> trait_of_assoc 2025-07-28 09:53:50 -05:00
bors
d242a8bd5a Auto merge of #144469 - Kivooeo:chains-cleanup, r=SparrowLii
Some `let chains` clean-up

Not sure if this kind of clean-up is welcoming because of size, but I decided to try out one

r? compiler
2025-07-28 05:25:23 +00:00
Kivooeo
b8eb046e6e use let chains in mir, resolve, target 2025-07-28 06:10:36 +05:00
Matthias Krüger
d88aa06cd9 Rollup merge of #144448 - camsteffen:defaultness-impl-trait-only, r=compiler-errors
Limit defaultness query to impl of trait

I separated this out from https://github.com/rust-lang/rust/pull/144386.
2025-07-26 15:28:02 +02:00
Cameron Steffen
cf4d7938cf Limit defaultness to impl of trait 2025-07-25 08:49:31 -05:00
Oli Scherer
e44a7386c2 Remove dead code and extend test coverage and diagnostics around it
We lost the following comment during refactorings:

The current code for niche-filling relies on variant indices instead of actual discriminants, so enums with explicit discriminants (RFC 2363) would misbehave.
2025-07-24 10:21:20 +00:00
Matthias Krüger
f78cc42032 Rollup merge of #143793 - fmease:lta-opaq-inf-recur, r=oli-obk
Opaque type collection: Guard against endlessly recursing free alias types

See test description for technical details.

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

r? oli-obk (sry, your queue is large, so no rush & feel free to reassign)
2025-07-17 10:41:45 +02:00
Camille GILLOT
21fd82adbc Retire hir::*ItemRef. 2025-07-13 13:50:01 +00:00
Camille GILLOT
277b0ecf34 Remove hir::AssocItemKind. 2025-07-13 13:50:00 +00:00
Camille GILLOT
3ecd03bdfd Move trait_item_def_id from ImplItemRef to ImplItem. 2025-07-13 13:50:00 +00:00