From bfb48b782a2a1106a32fa5b591295cec78c9de24 Mon Sep 17 00:00:00 2001 From: Ding Xiang Fei Date: Mon, 11 Nov 2024 06:49:20 +0800 Subject: [PATCH] detect cycle in type structure --- .../src/lint_tail_expr_drop_order.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_mir_transform/src/lint_tail_expr_drop_order.rs b/compiler/rustc_mir_transform/src/lint_tail_expr_drop_order.rs index 4f151fe4ea11..0f6592bb5110 100644 --- a/compiler/rustc_mir_transform/src/lint_tail_expr_drop_order.rs +++ b/compiler/rustc_mir_transform/src/lint_tail_expr_drop_order.rs @@ -221,6 +221,7 @@ fn extract_component_raw<'tcx>( tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, ty: Ty<'tcx>, + ty_seen: &mut UnordSet>, ) -> SmallVec<[Ty<'tcx>; 4]> { // Droppiness does not depend on regions, so let us erase them. let ty = tcx.try_normalize_erasing_regions(param_env, ty).unwrap_or(ty); @@ -232,10 +233,14 @@ fn extract_component_raw<'tcx>( if let Some(tys) = true_significant_drop_ty(tcx, ty) { // Some types can be further opened up because the drop is simply delegated for ty in tys { - out_tys.extend(extract_component_raw(tcx, param_env, ty)); + if ty_seen.insert(ty) { + out_tys.extend(extract_component_raw(tcx, param_env, ty, ty_seen)); + } } } else { - out_tys.push(ty); + if ty_seen.insert(ty) { + out_tys.push(ty); + } } } out_tys @@ -247,7 +252,7 @@ fn extract_component_with_significant_dtor<'tcx>( param_env: ty::ParamEnv<'tcx>, ty: Ty<'tcx>, ) -> SmallVec<[Ty<'tcx>; 4]> { - let mut tys = extract_component_raw(tcx, param_env, ty); + let mut tys = extract_component_raw(tcx, param_env, ty, &mut Default::default()); let mut deduplicate = FxHashSet::default(); tys.retain(|oty| deduplicate.insert(*oty)); tys.into_iter().collect()