Pass origin down to impl_trait_ty_to_ty

This commit is contained in:
Santiago Pastorino 2022-05-20 15:29:45 -03:00
parent 1e6ed67d37
commit b239611451
No known key found for this signature in database
GPG Key ID: 8131A24E0C79EFAF

View File

@ -23,7 +23,7 @@ use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::{walk_generics, Visitor as _};
use rustc_hir::lang_items::LangItem;
use rustc_hir::{GenericArg, GenericArgs};
use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin};
use rustc_middle::middle::stability::AllowUnstable;
use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, Subst, SubstsRef};
use rustc_middle::ty::GenericParamDefKind;
@ -2628,16 +2628,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let def_id = item_id.def_id.to_def_id();
match opaque_ty.kind {
hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => self
.impl_trait_ty_to_ty(
def_id,
lifetimes,
matches!(
origin,
hir::OpaqueTyOrigin::FnReturn(..)
| hir::OpaqueTyOrigin::AsyncFn(..)
),
),
hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => {
self.impl_trait_ty_to_ty(def_id, lifetimes, origin)
}
ref i => bug!("`impl Trait` pointed to non-opaque type?? {:#?}", i),
}
}
@ -2706,7 +2699,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
&self,
def_id: DefId,
lifetimes: &[hir::GenericArg<'_>],
replace_parent_lifetimes: bool,
origin: OpaqueTyOrigin,
) -> Ty<'tcx> {
debug!("impl_trait_ty_to_ty(def_id={:?}, lifetimes={:?})", def_id, lifetimes);
let tcx = self.tcx();
@ -2736,7 +2729,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// For `impl Trait` in the types of statics, constants,
// locals and type aliases. These capture all parent
// lifetimes, so they can use their identity subst.
GenericParamDefKind::Lifetime if replace_parent_lifetimes => {
GenericParamDefKind::Lifetime
if matches!(
origin,
hir::OpaqueTyOrigin::FnReturn(..) | hir::OpaqueTyOrigin::AsyncFn(..)
) =>
{
tcx.lifetimes.re_static.into()
}
_ => tcx.mk_param_from_def(param),