diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2022-12-04 14:18:52 +0000 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2022-12-04 14:38:20 +0000 |
| commit | e2d41f4c974f0cc09e5aafb02883f222487610f9 (patch) | |
| tree | cb9f547a45395ba89f8b6b87e0da3e8f90be2984 | |
| parent | cab4fd678c5b148a330f2bf255bf28a67dfea0fc (diff) | |
| download | rust-e2d41f4c974f0cc09e5aafb02883f222487610f9.tar.gz rust-e2d41f4c974f0cc09e5aafb02883f222487610f9.zip | |
Make nested RPITIT inherit the parent opaque's generics.
| -rw-r--r-- | compiler/rustc_hir_analysis/src/collect/generics_of.rs | 16 | ||||
| -rw-r--r-- | src/test/ui/async-await/in-trait/nested-rpit.rs | 17 |
2 files changed, 18 insertions, 15 deletions
diff --git a/compiler/rustc_hir_analysis/src/collect/generics_of.rs b/compiler/rustc_hir_analysis/src/collect/generics_of.rs index 639f81f20bf..0a7e25300cb 100644 --- a/compiler/rustc_hir_analysis/src/collect/generics_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/generics_of.rs @@ -4,7 +4,6 @@ use hir::{ GenericParamKind, HirId, Node, }; use rustc_hir as hir; -use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; use rustc_middle::ty::{self, TyCtxt}; use rustc_session::lint; @@ -143,20 +142,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics { Some(tcx.typeck_root_def_id(def_id)) } Node::Item(item) => match item.kind { - ItemKind::OpaqueTy(hir::OpaqueTy { - origin: - hir::OpaqueTyOrigin::FnReturn(fn_def_id) | hir::OpaqueTyOrigin::AsyncFn(fn_def_id), - in_trait, - .. - }) => { - if in_trait { - assert!(matches!(tcx.def_kind(fn_def_id), DefKind::AssocFn)) - } else { - assert!(matches!(tcx.def_kind(fn_def_id), DefKind::AssocFn | DefKind::Fn)) - } - Some(fn_def_id.to_def_id()) - } - ItemKind::OpaqueTy(hir::OpaqueTy { origin: hir::OpaqueTyOrigin::TyAlias, .. }) => { + ItemKind::OpaqueTy(hir::OpaqueTy { .. }) => { let parent_id = tcx.hir().get_parent_item(hir_id); assert_ne!(parent_id, hir::CRATE_OWNER_ID); debug!("generics_of: parent of opaque ty {:?} is {:?}", def_id, parent_id); diff --git a/src/test/ui/async-await/in-trait/nested-rpit.rs b/src/test/ui/async-await/in-trait/nested-rpit.rs new file mode 100644 index 00000000000..ae8e0aed0cc --- /dev/null +++ b/src/test/ui/async-await/in-trait/nested-rpit.rs @@ -0,0 +1,17 @@ +// check-pass +// edition: 2021 + +#![feature(async_fn_in_trait)] +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +use std::future::Future; +use std::marker::PhantomData; + +trait Lockable<K, V> { + async fn lock_all_entries(&self) -> impl Future<Output = Guard<'_>>; +} + +struct Guard<'a>(PhantomData<&'a ()>); + +fn main() {} |
