about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/ty
AgeCommit message (Collapse)AuthorLines
2025-07-20Rollup merge of #144216 - Nadrieril:revert-pin-hack, r=compiler-errorsJacob Pratt-16/+0
Don't consider unstable fields always-inhabited This reverts the hack in https://github.com/rust-lang/rust/pull/133889 now that `Pin`'s field is no longer public. Fixes https://github.com/rust-lang/rust/issues/143468. r? ```@compiler-errors```
2025-07-20Don't consider unstable fields always-inhabitedNadrieril-16/+0
This reverts the hack in https://github.com/rust-lang/rust/pull/133889 now that `Pin`'s field is no longer public.
2025-07-20Rollup merge of #144148 - compiler-errors:async-print-hack, r=lqdMatthias Krüger-25/+1
Remove pretty print hack for async blocks I introduced this hack 3 years ago, but it's not needed anymore, probably due to https://github.com/rust-lang/rust/pull/104321.
2025-07-18Remove pretty print hack for async blocksMichael Goulet-25/+1
2025-07-18Auto merge of #143845 - cjgillot:stability-query, r=jieyouxubors-5/+1
Split-up stability_index query This PR aims to move deprecation and stability processing away from the monolithic `stability_index` query, and directly implement `lookup_{deprecation,stability,body_stability,const_stability}` queries. The basic idea is to: - move per-attribute sanity checks into `check_attr.rs`; - move attribute compatibility checks into the `MissingStabilityAnnotations` visitor; - progressively dismantle the `Annotator` visitor and the `stability_index` query. The first commit contains functional change, and now warns when `#[automatically_derived]` is applied on a non-trait impl block. The other commits should not change visible behaviour. Perf in https://github.com/rust-lang/rust/pull/143845#issuecomment-3066308630 shows small but consistent improvement, except for unused-warnings case. That case being a stress test, I'm leaning towards accepting the regression. This PR changes `check_attr`, so has a high conflict rate on that file. This should not cause issues for review.
2025-07-18Auto merge of #143545 - compiler-errors:coroutine-obl, r=oli-obkbors-1/+19
`-Zhigher-ranked-assumptions`: Consider WF of coroutine witness when proving outlives assumptions ### TL;DR This PR introduces an unstable flag `-Zhigher-ranked-assumptions` which tests out a new algorithm for dealing with some of the higher-ranked outlives problems that come from auto trait bounds on coroutines. See: * rust-lang/rust#110338 While it doesn't fix all of the issues, it certainly fixed many of them, so I'd like to get this landed so people can test the flag on their own code. ### Background Consider, for example: ```rust use std::future::Future; trait Client { type Connecting<'a>: Future + Send where Self: 'a; fn connect(&self) -> Self::Connecting<'_>; } fn call_connect<C>(c: C) -> impl Future + Send where C: Client + Send + Sync, { async move { c.connect().await } } ``` Due to the fact that we erase the lifetimes in a coroutine, we can think of the interior type of the async block as something like: `exists<'r, 's> { C, &'r C, C::Connecting<'s> }`. The first field is the `c` we capture, the second is the auto-ref that we perform on the call to `.connect()`, and the third is the resulting future we're awaiting at the first and only await point. Note that every region is uniquified differently in the interior types. For the async block to be `Send`, we must prove that both of the interior types are `Send`. First, we have an `exists<'r, 's>` binder, which needs to be instantiated universally since we treat the regions in this binder as *unknown*[^exist]. This gives us two types: `{ &'!r C, C::Connecting<'!s> }`. Proving `&'!r C: Send` is easy due to a [`Send`](https://doc.rust-lang.org/nightly/std/marker/trait.Send.html#impl-Send-for-%26T) impl for references. Proving `C::Connecting<'!s>: Send` can only be done via the item bound, which then requires `C: '!s` to hold (due to the `where Self: 'a` on the associated type definition). Unfortunately, we don't know that `C: '!s` since we stripped away any relationship between the interior type and the param `C`. This leads to a bogus borrow checker error today! ### Approach Coroutine interiors are well-formed by virtue of them being borrow-checked, as long as their callers are invoking their parent functions in a well-formed way, then substitutions should also be well-formed. Therefore, in our example above, we should be able to deduce the assumption that `C: '!s` holds from the well-formedness of the interior type `C::Connecting<'!s>`. This PR introduces the notion of *coroutine assumptions*, which are the outlives assumptions that we can assume hold due to the well-formedness of a coroutine's interior types. These are computed alongside the coroutine types in the `CoroutineWitnessTypes` struct. When we instantiate the binder when proving an auto trait for a coroutine, we instantiate the `CoroutineWitnessTypes` and stash these newly instantiated assumptions in the region storage in the `InferCtxt`. Later on in lexical region resolution or MIR borrowck, we use these registered assumptions to discharge any placeholder outlives obligations that we would otherwise not be able to prove. ### How well does it work? I've added a ton of tests of different reported situations that users have shared on issues like rust-lang/rust#110338, and an (anecdotally) large number of those examples end up working straight out of the box! Some limitations are described below. ### How badly does it not work? The behavior today is quite rudimentary, since we currently discharge the placeholder assumptions pretty early in region resolution. This manifests itself as some limitations on the code that we accept. For example, `tests/ui/async-await/higher-ranked-auto-trait-11.rs` continues to fail. In that test, we must prove that a placeholder is equal to a universal for a param-env candidate to hold when proving an auto trait, e.g. `'!1 = 'a` is required to prove `T: Trait<'!1>` in a param-env that has `T: Trait<'a>`. Unfortunately, at that point in the MIR body, we only know that the placeholder is equal to some body-local existential NLL var `'?2`, which only gets equated to the universal `'a` when being stored into the return local later on in MIR borrowck. This could be fixed by integrating these assumptions into the type outlives machinery in a more first-class way, and delaying things to the end of MIR typeck when we know the full relationship between existential and universal NLL vars. Doing this integration today is quite difficult today. `tests/ui/async-await/higher-ranked-auto-trait-11.rs` fails because we don't compute the full transitive outlives relations between placeholders. In that test, we have in our region assumptions that some `'!1 = '!2` and `'!2 = '!3`, but we must prove `'!1 = '!3`. This can be fixed by computing the set of coroutine outlives assumptions in a more transitive way, or as I mentioned above, integrating these assumptions into the type outlives machinery in a more first-class way, since it's already responsible for the transitive outlives assumptions of universals. ### Moving forward I'm still quite happy with this implementation, and I'd like to land it for testing. I may work on overhauling both the way we compute these coroutine assumptions and also how we deal with the assumptions during (lexical/nll) region checking. But for now, I'd like to give users a chance to try out this new `-Zhigher-ranked-assumptions` flag to uncover more shortcomings. [^exist]: Instantiating this binder with infer regions would be incomplete, since we'd be asking for *some* instantiation of the interior types, not proving something for *all* instantiations of the interior types.
2025-07-17Retire stability_index query.Camille GILLOT-5/+1
2025-07-17Auto merge of #141762 - compiler-errors:witnesser, r=lcnrbors-11/+7
Unify `CoroutineWitness` sooner in typeck, and stall coroutine obligations based off of `TypingEnv` * Stall coroutine obligations based off of `TypingMode` in the old solver. * Eagerly assign `TyKind::CoroutineWitness` to the witness arg of coroutines during typeck, rather than deferring them to the end of typeck. r? lcnr This is part of https://github.com/rust-lang/rust/issues/143017.
2025-07-17Eagerly unify coroutine witness in old solverMichael Goulet-11/+7
2025-07-17parse `const trait Trait`Deadbeef-1/+1
2025-07-17Auto merge of #144044 - fmease:rollup-kg413pt, r=fmeasebors-1/+1
Rollup of 15 pull requests Successful merges: - rust-lang/rust#142304 (tests: Add `RUST_BACKTRACE` and `-Cpanic` revisions to `panic-main.rs` test) - rust-lang/rust#143388 (Various refactors to the LTO handling code) - rust-lang/rust#143409 (Enable xgot feature for mips64 musl targets) - rust-lang/rust#143592 (UWP: link ntdll functions using raw-dylib) - rust-lang/rust#143595 (add `const_make_global`; err for `const_allocate` ptrs if didn't call) - rust-lang/rust#143678 (Added error for invalid char cast) - rust-lang/rust#143820 (Fixed a core crate compilation failure when enabling the `optimize_for_size` feature on some targets) - rust-lang/rust#143829 (Trim `BorrowedCursor` API) - rust-lang/rust#143851 (ci cleanup: rustdoc-gui-test now installs browser-ui-test) - rust-lang/rust#143856 (Linting public reexport of private dependencies) - rust-lang/rust#143895 (Dont collect assoc ty item bounds from trait where clause for host effect predicates) - rust-lang/rust#143922 (Improve path segment joining) - rust-lang/rust#143964 (Fix handling of SCRIPT_ARG in docker images) - rust-lang/rust#144002 (Update poison.rs) - rust-lang/rust#144016 (trait_sel: `MetaSized` always holds temporarily) r? `@ghost` `@rustbot` modify labels: rollup
2025-07-17Auto merge of #140399 - tiif:unstable_impl, r=lcnr,BoxyUwUbors-0/+12
Implement unstable trait impl This PR allows marking impls of stable trait with stable type as unstable. ## Approach In std/core, an impl can be marked as unstable by annotating it with ``#[unstable_feature_bound(feat_name)]``. This will add a ``ClauseKind::Unstable_Feature(feat_name)`` to the list of predicates in ``predicates_of`` . When an unstable impl's function is called, we will first iterate through all the goals in ``param_env`` to check if there is any ``ClauseKind::UnstableFeature(feat_name)`` in ``param_env``. The existence of ``ClauseKind::Unstable_Feature(feat_name)`` in ``param_env`` means an``#[unstable_feature_bound(feat_name)]`` is present at the call site of the function, so we allow the check to succeed in this case. If ``ClauseKind::UnstableFeature(feat_name)`` does not exist in ``param_env``, we will still allow the check to succeed for either of the cases below: 1. The feature is enabled through ``#[feature(feat_name)]`` outside of std / core. 2. We are in codegen because we may be monomorphizing a body from an upstream crate which had an unstable feature enabled that the downstream crate do not. For the rest of the case, it will fail with ambiguity. ## Limitation In this PR, we do not support: 1. using items that need ``#[unstable_feature_bound]`` within stable APIs 2. annotate main function with ``#[unstable_feature_bound]`` 3. annotate ``#[unstable_feature_bound]`` on items other than free function and impl ## Acknowledgement The design and mentoring are done by `@BoxyUwU`
2025-07-17Use `join_path_syms` in one more place.Nicholas Nethercote-1/+1
This one is a bit marginal, because the segments are a mix of symbols and strings.
2025-07-16resolve: Merge `NameBindingKind::Module` into `NameBindingKind::Res`Vadim Petrochenkov-3/+1
2025-07-15Add alias for ArgOutlivesPredicateMichael Goulet-7/+8
2025-07-15Deduce outlives obligations from WF of coroutine interior typesMichael Goulet-0/+11
2025-07-15Add outlives to CoroutineWitnessTypesMichael Goulet-0/+6
2025-07-15Implement other logicstiif-0/+5
2025-07-15Add the core logic in old and new solverstiif-0/+7
2025-07-15Define datastructures for `#[cfg]` attribute, move StrippedCfgItemJonathan Brouwer-3/+2
2025-07-14Auto merge of #143779 - JonathanBrouwer:automatically_derived_parser, r=oli-obkbors-2/+2
Port `#[automatically_derived]` to the new attribute parsing infrastructure Ports `#[automatically_derived]` to the new attribute parsing infrastructure for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971351163 r? `@oli-obk` cc `@jdonszelmann`
2025-07-13Generalize TyCtxt::item_name.Camille GILLOT-5/+9
2025-07-13Remove hir::AssocItemKind.Camille GILLOT-0/+10
2025-07-12Clean up implementation of RPITIT assoc item loweringMichael Goulet-21/+23
2025-07-13query RPITIT in a trait or implbohan-2/+23
2025-07-12Port `#[automatically_derived]` to the new attribute parsing infrastructureJonathan Brouwer-2/+2
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-11Rollup merge of #143716 - ↵Matthias Krüger-8/+6
workingjubilee:document-some-codegen-backend-stuff, r=bjorn3,fee1-dead compiler: doc/comment some codegen-for-functions interfaces An out-of-date comment gets updated and some underdocumented functions get documented.
2025-07-11Rollup merge of #143403 - GrigorenkoPV:attributes/traits, r=jdonszelmannMatthias Krüger-11/+8
Port several trait/coherence-related attributes the new attribute system Part of rust-lang/rust#131229 This ports: - `#[const_trait]` - `#[rustc_deny_explicit_impl]` - `#[rustc_do_not_implement_via_object]` - `#[rustc_coinductive]` - `#[type_const]` - `#[rustc_specialization_trait]` - `#[rustc_unsafe_specialization_marker]` - `#[marker]` - `#[fundamental]` - `#[rustc_paren_sugar]` - `#[rustc_allow_incoherent_impl]` - `#[rustc_coherence_is_core]` This also changes `#[marker]` to error on duplicates instead of warning. cc rust-lang/rust#142838, but I don't think it matters too much, since it's unstable. r? ``@oli-obk``
2025-07-10Rollup merge of #143744 - fmease:lta-expand-proper-depth, r=compiler-errorsTrevor Gross-2/+4
Properly track the depth when expanding free alias types Decrease the depth after the fold so as not to affect the depth for unrelated same-level constituent types. My bad. Fixes rust-lang/rust#142419.
2025-07-10Properly track the depth when expanding free alias typesLeón Orell Valerian Liehr-2/+4
2025-07-09compiler: recomment `needs_fn_once_adapter_shim`Jubilee Young-8/+6
This requires digging up ffee9566bbd7728e6411e6094105d6905373255d and reading the comments there to understand that the callee in resolve_closure previously directly handled a function pointer value.
2025-07-09Add opaque TypeId handles for CTFEOli Scherer-0/+1
2025-07-09Port `#[fundamental]` to the new attribute systemPavel Grigorenko-2/+1
2025-07-09Port `#[type_const]` to the new attribute systemPavel Grigorenko-2/+3
2025-07-09Port `#[const_trait]` to the new attribute systemPavel Grigorenko-7/+4
2025-07-07Auto merge of #143182 - xdoardo:more-addrspace, r=workingjubileebors-7/+7
Allow custom default address spaces and parse `p-` specifications in the datalayout string Some targets, such as CHERI, use as default an address space different from the "normal" default address space `0` (in the case of CHERI, [200 is used](https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-877.pdf)). Currently, `rustc` does not allow to specify custom address spaces and does not take into consideration [`p-` specifications in the datalayout string](https://llvm.org/docs/LangRef.html#langref-datalayout). This patch tries to mitigate these problems by allowing targets to define a custom default address space (while keeping the default value to address space `0`) and adding the code to parse the `p-` specifications in `rustc_abi`. The main changes are that `TargetDataLayout` now uses functions to refer to pointer-related informations, instead of having specific fields for the size and alignment of pointers in the default address space; furthermore, the two `pointer_size` and `pointer_align` fields in `TargetDataLayout` are replaced with an `FxHashMap` that holds info for all the possible address spaces, as parsed by the `p-` specifications. The potential performance drawbacks of not having ad-hoc fields for the default address space will be tested in this PR's CI run. r? workingjubilee
2025-07-07compiler: Parse `p-` specs in datalayout string, allow definition of custom ↵Edoardo Marangoni-7/+7
default data address space
2025-07-06Rewrite empty attribute lintJonathan Brouwer-5/+2
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-05Auto merge of #139598 - compiler-errors:no-bound-var-symbol, r=WaffleLapkinbors-145/+109
Remove `Symbol` from `Named` variant of `BoundRegionKind`/`LateParamRegionKind` The `Symbol` is redundant, since we already store a `DefId` in the region variant. Instead, load the name via `item_name` when needed (which is almost always on the diagnostic path). This introduces a `BoundRegionKind::NamedAnon` which is used for giving anonymous bound regions names, but which should only be used during pretty printing and error reporting.
2025-07-05Rollup merge of #143372 - cjgillot:bare-glob-map, r=petrochenkovMatthias Krüger-4/+0
Remove names_imported_by_glob_use query. Based on https://github.com/rust-lang/rust/pull/143247 r? ``@ghost`` for perf
2025-07-05Rollup merge of #143085 - JonathanBrouwer:non_exhaustive_parser, r=jdonszelmannMatthias Krüger-1/+4
Port `#[non_exhaustive]` to the new attribute parsing infrastructure Ports `non_exhaustive` to the new attribute parsing infrastructure for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971353197 r? ``@jdonszelmann``
2025-07-04Port `#[non_exhaustive]` to the new attribute parsing infrastructureJonathan Brouwer-1/+4
2025-07-04NitsMichael Goulet-1/+1
2025-07-04Fix elided lifetimes in rustdocMichael Goulet-4/+4
2025-07-04Fix pretty printing of placeholder typesMichael Goulet-8/+12
2025-07-04Same for typesMichael Goulet-6/+6
2025-07-04Remove Symbol for Named LateParam/Bound variantsMichael Goulet-130/+90
2025-07-04Auto merge of #114669 - cjgillot:metadata-wp, r=petrochenkovbors-0/+4
Make metadata a workproduct and reuse it This PR aims to skip the generation of metadata by reusing the infrastructure that already exists for compiled codegen-units, namely "workproducts". This can yield substantial gains (~10%) when we can demonstrate that metadata does not change between an incremental session and the next. This is the case if the crate is unchanged, or if all the changes are in upstream crates and have no effect on it. This latter case is most interesting, as it arises regularly for users with several crates in their workspace. TODO: - [x] Materialize the fact that metadata encoding relies on the relative order of definitions; - [x] Refactor the handling of doc links.
2025-07-04Rollup merge of #143308 - compiler-errors:no-pointer-like, r=oli-obkMatthias Krüger-5/+9
Remove `PointerLike` trait r? oli-obk
2025-07-04Reuse metadata file from work products.Camille GILLOT-0/+4