Skip to content

Commit

Permalink
detect cycle in type structure
Browse files Browse the repository at this point in the history
  • Loading branch information
dingxiangfei2009 committed Nov 10, 2024
1 parent 497537a commit bfb48b7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions compiler/rustc_mir_transform/src/lint_tail_expr_drop_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ fn extract_component_raw<'tcx>(
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
ty: Ty<'tcx>,
ty_seen: &mut UnordSet<Ty<'tcx>>,
) -> 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);
Expand All @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit bfb48b7

Please sign in to comment.