diff options
| author | lcnr <rust@lcnr.de> | 2025-08-12 16:33:21 +0200 |
|---|---|---|
| committer | lcnr <rust@lcnr.de> | 2025-08-13 14:10:19 +0200 |
| commit | f979bf018ff9a44118fabb96ea039903c47fb5e3 (patch) | |
| tree | ec4270cdb6805b86632d6554839340aaeaf073d2 /compiler/rustc_middle/src/ty | |
| parent | 3339fa5fcce74dd219f23988d6d9cabfd6871cb6 (diff) | |
| download | rust-f979bf018ff9a44118fabb96ea039903c47fb5e3.tar.gz rust-f979bf018ff9a44118fabb96ea039903c47fb5e3.zip | |
`fn new_coroutine_witness_for_coroutine` woops
Diffstat (limited to 'compiler/rustc_middle/src/ty')
| -rw-r--r-- | compiler/rustc_middle/src/ty/sty.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 9a2a140efd3..755fc68d86f 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -830,6 +830,31 @@ impl<'tcx> Ty<'tcx> { Ty::new(tcx, CoroutineWitness(def_id, args)) } + pub fn new_coroutine_witness_for_coroutine( + tcx: TyCtxt<'tcx>, + def_id: DefId, + coroutine_args: GenericArgsRef<'tcx>, + ) -> Ty<'tcx> { + tcx.debug_assert_args_compatible(def_id, coroutine_args); + // HACK: Coroutine witness types are lifetime erased, so they + // never reference any lifetime args from the coroutine. We erase + // the regions here since we may get into situations where a + // coroutine is recursively contained within itself, leading to + // witness types that differ by region args. This means that + // cycle detection in fulfillment will not kick in, which leads + // to unnecessary overflows in async code. See the issue: + // <https://github.com/rust-lang/rust/issues/145151>. + let args = + ty::GenericArgs::for_item(tcx, tcx.typeck_root_def_id(def_id), |def, _| { + match def.kind { + ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(), + ty::GenericParamDefKind::Type { .. } + | ty::GenericParamDefKind::Const { .. } => coroutine_args[def.index as usize], + } + }); + Ty::new_coroutine_witness(tcx, def_id, args) + } + // misc #[inline] @@ -988,6 +1013,14 @@ impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> { Ty::new_coroutine_witness(interner, def_id, args) } + fn new_coroutine_witness_for_coroutine( + interner: TyCtxt<'tcx>, + def_id: DefId, + coroutine_args: ty::GenericArgsRef<'tcx>, + ) -> Self { + Ty::new_coroutine_witness_for_coroutine(interner, def_id, coroutine_args) + } + fn new_ptr(interner: TyCtxt<'tcx>, ty: Self, mutbl: hir::Mutability) -> Self { Ty::new_ptr(interner, ty, mutbl) } |
