about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src/collect
AgeCommit message (Collapse)AuthorLines
2023-01-04rename get_parent_node to parent_idMichael Goulet-8/+8
2022-12-29Rollup merge of #106221 - Nilstrieb:rptr-more-like-ref-actually, ↵Matthias Krüger-1/+1
r=compiler-errors Rename `Rptr` to `Ref` in AST and HIR The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already as well.
2022-12-28Rework hir Bounds collectionMichael Goulet-10/+9
2022-12-28Rename `Rptr` to `Ref` in AST and HIRNilstrieb-1/+1
The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already as well.
2022-12-27Shorten type in noteEsteban Küber-6/+7
2022-12-20rustc: Remove needless lifetimesJeremy Stucki-5/+5
2022-12-14Auto merge of #104986 - compiler-errors:opaques, r=oli-obkbors-8/+8
Combine `ty::Projection` and `ty::Opaque` into `ty::Alias` Implements https://github.com/rust-lang/types-team/issues/79. This PR consolidates `ty::Projection` and `ty::Opaque` into a single `ty::Alias`, with an `AliasKind` and `AliasTy` type (renamed from `ty::ProjectionTy`, which is the inner data of `ty::Projection`) defined as so: ``` enum AliasKind { Projection, Opaque, } struct AliasTy<'tcx> { def_id: DefId, substs: SubstsRef<'tcx>, } ``` Since we don't have access to `TyCtxt` in type flags computation, and because repeatedly calling `DefKind` on the def-id is expensive, these two types are distinguished with `ty::AliasKind`, conveniently glob-imported into `ty::{Projection, Opaque}`. For example: ```diff match ty.kind() { - ty::Opaque(..) => + ty::Alias(ty::Opaque, ..) => {} _ => {} } ``` This PR also consolidates match arms that treated `ty::Opaque` and `ty::Projection` identically. r? `@ghost`
2022-12-13Combine projection and opaque into aliasMichael Goulet-4/+4
2022-12-13ProjectionTy.item_def_id -> ProjectionTy.def_idMichael Goulet-2/+2
2022-12-13Use ty::OpaqueTy everywhereMichael Goulet-2/+2
2022-12-13Clarify explicit_predicates_of is_assoc_item_ty commentSantiago Pastorino-3/+4
2022-12-12Join match arms since they do the same thingSantiago Pastorino-5/+1
2022-12-12Fix typoSantiago Pastorino-1/+1
2022-12-10Rollup merge of #105410 - TaKO8Ki:fix-105257, r=BoxyUwUMatthias Krüger-1/+1
Consider `parent_count` for const param defaults Fixes #105257
2022-12-08add a test case for `generic_const_exprs` in trait itemsTakayuki Maeda-1/+1
2022-12-07consider `parent_count` for const param defaultsTakayuki Maeda-1/+1
2022-12-04Make nested RPITIT inherit the parent opaque's generics.Camille GILLOT-15/+1
2022-12-01rustc_hir: Relax lifetime requirements on `Visitor::visit_path`Vadim Petrochenkov-1/+1
2022-11-27Auto merge of #104048 - cjgillot:split-lifetime, r=compiler-errorsbors-49/+54
Separate lifetime ident from lifetime resolution in HIR Drive-by: change how suggested generic args are computed. Fixes https://github.com/rust-lang/rust/issues/103815 I recommend reviewing commit-by-commit.
2022-11-25Introduce PredicateKind::ClauseSantiago Pastorino-17/+21
2022-11-24Use kw::Empty for elided lifetimes in path.Camille GILLOT-6/+8
2022-11-23Separate lifetime ident from resolution in HIR.Camille GILLOT-50/+53
2022-11-21Auto merge of #103491 - cjgillot:self-rpit, r=oli-obkbors-52/+71
Support using `Self` or projections inside an RPIT/async fn I reuse the same idea as https://github.com/rust-lang/rust/pull/103449 to use variances to encode whether a lifetime parameter is captured by impl-trait. The current implementation of async and RPIT replace all lifetimes from the parent generics by `'static`. This PR changes the scheme ```rust impl<'a> Foo<'a> { fn foo<'b, T>() -> impl Into<Self> + 'b { ... } } opaque Foo::<'_a>::foo::<'_b, T>::opaque<'b>: Into<Foo<'_a>> + 'b; impl<'a> Foo<'a> { // OLD fn foo<'b, T>() -> Foo::<'static>::foo::<'static, T>::opaque::<'b> { ... } ^^^^^^^ the `Self` becomes `Foo<'static>` // NEW fn foo<'b, T>() -> Foo::<'a>::foo::<'b, T>::opaque::<'b> { ... } ^^ the `Self` stays `Foo<'a>` } ``` There is the same issue with projections. In the example, substitute `Self` by `<T as Trait<'b>>::Assoc` in the sugared version, and `Foo<'_a>` by `<T as Trait<'_b>>::Assoc` in the desugared one. This allows to support `Self` in impl-trait, since we do not replace lifetimes by `'static` any more. The same trick allows to use projections like `T::Assoc` where `Self` is allowed. The feature is gated behind a `impl_trait_projections` feature gate. The implementation relies on 2 tweaking rules for opaques in 2 places: - we only relate substs that correspond to captured lifetimes during TypeRelation; - we only list captured lifetimes in choice region computation. For simplicity, I encoded the "capturedness" of lifetimes as a variance, `Bivariant` vs `Invariant` for unused vs captured lifetimes. The `variances_of` query used to ICE for opaques. Impl-trait that do not reference `Self` or projections will have their variances as: - `o` (invariant) for each parent type or const; - `*` (bivariant) for each parent lifetime --> will not participate in borrowck; - `o` (invariant) for each own lifetime. Impl-trait that does reference `Self` and/or projections will have some parent lifetimes marked as `o` (as the example above), and participate in type relation and borrowck. In the example above, `variances_of(opaque) = ['_a: o, '_b: *, T: o, 'b: o]`. r? types cc `@compiler-errors` , as you asked about the issue with `Self` and projections.
2022-11-13Store a LocalDefId in hir::AnonConst.Camille GILLOT-3/+2
2022-11-13Store a LocalDefId in hir::GenericParam.Camille GILLOT-45/+32
2022-11-13Store LocalDefId in hir::Closure.Camille GILLOT-6/+4
2022-11-13Create bidirectional bounds between original and duplicated parameters.Camille GILLOT-32/+71
2022-11-12Verify predicates on RPIT and async opaques.Camille GILLOT-20/+0
2022-11-11Clean-up formatting.Camille GILLOT-5/+4
2022-11-11Resolve lifetimes using the regular logic for RPIT.Camille GILLOT-37/+36
2022-11-11Resolve lifetimes independently for each item-like.Camille GILLOT-177/+66
2022-11-08Rollup merge of #100508 - BoxyUwU:make_less_things_late_bound, r=nikomatsakisManish Goregaokar-5/+99
avoid making substs of type aliases late bound when used as fn args fixes #47511 fixes #85533 (although I did not know theses issues existed when i was working on this :upside_down_face:) currently `Alias<...>` is treated the same as `Struct<...>` when deciding if generics should be late bound or early bound but this is not correct as `Alias` might normalize to a projection which does not constrain the generics. I think this needs more tests before merging more explanation of PR [here](https://hackmd.io/v44a-QVjTIqqhK9uretyQg?view) Hackmd inline for future readers: --- This assumes reader is familiar with the concept of early/late bound lifetimes. There's a section on rustc-dev-guide if not (although i think some details are a bit out of date) ## problem & background Not all lifetimes on a fn can be late bound: ```rust fn foo<'a>() -> &'a (); impl<'a> Fn<()> for FooFnDef { type Output = &'a (); // uh oh unconstrained lifetime } ``` so we make make them early bound ```rust fn foo<'a>() -> &'a (); impl<'a> Fn<()> for FooFnDef<'a> {// wow look at all that lifetimey type Output = &'a (); } ``` (Closures have the same constraint however it is not enforced leading to soundness bugs, [#84385](https://github.com/rust-lang/rust/pull/84385) implements this "downgrading late bound to early bound" for closures) lifetimes on fn items are only late bound when they are "constrained" by the fn args: ```rust fn foo<'a>(_: &'a ()) -> &'a (); // late bound, not present on `FooFnItem` // vv impl<'a> Trait<(&'a (),)> for FooFnItem { type Output = &'a (); } // projections do not constrain inputs fn bar<'a, T: Trait>(_: <T as Trait<'a>>::Assoc) -> &'a (); // early bound // vv impl<'a, T: Trait> Fn<(<T as Trait<'a>>::Assoc,)> for BarFnItem<'a, T> { type Output = &'a (); } ``` current logic for determining if inputs "constrain" a lifetime works off of HIR so does not normalize aliases. It also assumes that any path with no self type constrains all its substs (i.e. `Foo<'a, u32>` has no self type but `T::Assoc` does). This falls apart for top level type aliases (see linked issues): ```rust type Alias<'a, T> = <T as Trait<'a>>::Assoc; // wow look its a path with no self type uwu // i bet that constrains `'a` so it should be latebound // vvvvvvvvvvv fn foo<'a, T: Trait>(_: Alias<'a, T>) -> &'a (); // `Alias` normalized to make things clearer // vvvvvvvvvvvvvvvvvvvvvvv impl<'a, T: Trait> Fn<(<T as Trait<'a>>::Assoc,)> for FooFnDef<T> { type Output = &'a (); // oh no `'a` isnt constrained wah wah waaaah *trumbone noises* // i think, idk what musical instrument that is } ``` ## solution The PR solves this by having the hir visitor that checks for lifetimes in constraining uses check if the path is a `DefKind::Alias`. If it is we ""normalize"" it by calling `type_of` and walking the returned type. This is a bit hacky as it requires a mapping between the substs on the path in hir, and the generics of the `type Alias<...>` which is on the ty layer. Alternative solutions may involve calculating the "late boundness" of lifetimes after/during astconv rather than relying on hir at all. We already have code to determine whether a lifetime SHOULD be late bound or not as this is currently how the error for `fn foo<'a, T: Trait>(_: Alias<'a, T>) -> &'a ();` gets emitted. It is probably not possible to do this right now, late boundness is used by `generics_of` and `gather_explicit_predicates_of` as we currently do not put late bound lifetimes in `Generics`. Although this seems sus to me as the long term goal is to make all generics late bound which would result in `generics_of(function)` being empty? [#103448](https://github.com/rust-lang/rust/pull/103448) places all lifetimes in `Generics` regardless of late boundness so that may be a good step towards making this possible.
2022-11-08commentBoxy-11/+23
2022-11-08add 'ty_error_with_guaranteed' and 'const_error_with_guaranteed'yukang-2/+2
2022-11-06fixyfixfixBoxy-5/+87
2022-11-04Rollup merge of #103780 - compiler-errors:bound-closure-lifetimes, r=jackh726Matthias Krüger-3/+4
Fix late-bound lifetime closure ICEs in HIR typeck and MIR borrowck During HIR typeck, we need to teach astconv to treat late-bound regions within a closure body as free, fixing escaping bound vars ICEs in both of the issues below. However, this then gets us to MIR borrowck, which itself needs to be taught how to instantiate free region vids for late-bound regions that come from items that _aren't_ the typeck root (for now, just closures). Fixes #103771 Fixes #103736
2022-11-01fix(generic_const_exprs): Fix predicate inheritance for children of opaque typesZhixing Zhang-2/+29
2022-10-31Free late-bound lifetimes in closures as wellMichael Goulet-3/+4
2022-10-29Rollup merge of #103618 - nnethercote:rename-OwnerId-fields, r=compiler-errorsGuillaume Gomez-20/+20
Rename some `OwnerId` fields. `@spastorino` noticed some silly expressions like `item_id.def_id.def_id`. This commit renames several `def_id: OwnerId` fields as `owner_id`, so those expressions become `item_id.owner_id.def_id`. `item_id.owner_id.local_def_id` would be even clearer, but the use of `def_id` for values of type `LocalDefId` is *very* widespread, so I left that alone. r? `@compiler-errors`
2022-10-29Rename some `OwnerId` fields.Nicholas Nethercote-20/+20
spastorino noticed some silly expressions like `item_id.def_id.def_id`. This commit renames several `def_id: OwnerId` fields as `owner_id`, so those expressions become `item_id.owner_id.def_id`. `item_id.owner_id.local_def_id` would be even clearer, but the use of `def_id` for values of type `LocalDefId` is *very* widespread, so I left that alone.
2022-10-29Rollup merge of #103383 - compiler-errors:tait-scope, r=oli-obkMatthias Krüger-0/+6
Note scope of TAIT more accurately This maybe explains why the person was confused in #101897, since we say "same module" but really should've said "same impl". r? ``@oli-obk``
2022-10-27tidy + move logic to fnBoxy-29/+4
2022-10-27use proper spansBoxy-5/+8
2022-10-27DoItBoxy-1/+31
2022-10-24Make param index generation a bit more robustOli Scherer-13/+14
2022-10-22Note scope of TAIT more accuratelyMichael Goulet-0/+6
2022-10-18change `ConstEvaluatable` to use `ty::Const`lcnr-2/+2
2022-10-13Auto merge of #102700 - oli-obk:0xDEAD_TAIT, r=compiler-errorsbors-26/+41
Check hidden types in dead code fixes #99490 r? `@compiler-errors` best reviewed commit by commit
2022-10-12Auto merge of #101679 - compiler-errors:rpitit-default-body, r=nikomatsakisbors-3/+2
Support default-body trait functions with return-position `impl Trait` in traits Introduce a new `Trait` candidate kind for the `ImplTraitInTrait` projection candidate, which just projects an RPITIT down to its opaque type form. This is a hack until we lower RPITITs to regular associated types, after which we will need to rework how these default bodies are type-checked, so comments are left in a few places for us to clean up later. Fixes #101665
2022-10-10Move lifetime resolution module to rustc_hir_analysis.Camille GILLOT-0/+1888