@@ -23,7 +23,7 @@ use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
23
23
use rustc_hir::def_id::{DefId, LocalDefId};
24
24
use rustc_hir::intravisit::{walk_generics, Visitor as _};
25
25
use rustc_hir::lang_items::LangItem;
26
- use rustc_hir::{GenericArg, GenericArgs};
26
+ use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin };
27
27
use rustc_middle::middle::stability::AllowUnstable;
28
28
use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, Subst, SubstsRef};
29
29
use rustc_middle::ty::GenericParamDefKind;
@@ -2628,16 +2628,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2628
2628
let def_id = item_id.def_id.to_def_id();
2629
2629
2630
2630
match opaque_ty.kind {
2631
- hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => self
2632
- .impl_trait_ty_to_ty(
2633
- def_id,
2634
- lifetimes,
2635
- matches!(
2636
- origin,
2637
- hir::OpaqueTyOrigin::FnReturn(..)
2638
- | hir::OpaqueTyOrigin::AsyncFn(..)
2639
- ),
2640
- ),
2631
+ hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => {
2632
+ self.impl_trait_ty_to_ty(def_id, lifetimes, origin)
2633
+ }
2641
2634
ref i => bug!("`impl Trait` pointed to non-opaque type?? {:#?}", i),
2642
2635
}
2643
2636
}
@@ -2706,7 +2699,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2706
2699
&self,
2707
2700
def_id: DefId,
2708
2701
lifetimes: &[hir::GenericArg<'_>],
2709
- replace_parent_lifetimes: bool ,
2702
+ origin: OpaqueTyOrigin ,
2710
2703
) -> Ty<'tcx> {
2711
2704
debug!("impl_trait_ty_to_ty(def_id={:?}, lifetimes={:?})", def_id, lifetimes);
2712
2705
let tcx = self.tcx();
@@ -2736,7 +2729,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2736
2729
// For `impl Trait` in the types of statics, constants,
2737
2730
// locals and type aliases. These capture all parent
2738
2731
// lifetimes, so they can use their identity subst.
2739
- GenericParamDefKind::Lifetime if replace_parent_lifetimes => {
2732
+ GenericParamDefKind::Lifetime
2733
+ if matches!(
2734
+ origin,
2735
+ hir::OpaqueTyOrigin::FnReturn(..) | hir::OpaqueTyOrigin::AsyncFn(..)
2736
+ ) =>
2737
+ {
2740
2738
tcx.lifetimes.re_static.into()
2741
2739
}
2742
2740
_ => tcx.mk_param_from_def(param),
0 commit comments