Skip to content

Commit bfb48b7

Browse files
detect cycle in type structure
1 parent 497537a commit bfb48b7

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

compiler/rustc_mir_transform/src/lint_tail_expr_drop_order.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ fn extract_component_raw<'tcx>(
221221
tcx: TyCtxt<'tcx>,
222222
param_env: ty::ParamEnv<'tcx>,
223223
ty: Ty<'tcx>,
224+
ty_seen: &mut UnordSet<Ty<'tcx>>,
224225
) -> SmallVec<[Ty<'tcx>; 4]> {
225226
// Droppiness does not depend on regions, so let us erase them.
226227
let ty = tcx.try_normalize_erasing_regions(param_env, ty).unwrap_or(ty);
@@ -232,10 +233,14 @@ fn extract_component_raw<'tcx>(
232233
if let Some(tys) = true_significant_drop_ty(tcx, ty) {
233234
// Some types can be further opened up because the drop is simply delegated
234235
for ty in tys {
235-
out_tys.extend(extract_component_raw(tcx, param_env, ty));
236+
if ty_seen.insert(ty) {
237+
out_tys.extend(extract_component_raw(tcx, param_env, ty, ty_seen));
238+
}
236239
}
237240
} else {
238-
out_tys.push(ty);
241+
if ty_seen.insert(ty) {
242+
out_tys.push(ty);
243+
}
239244
}
240245
}
241246
out_tys
@@ -247,7 +252,7 @@ fn extract_component_with_significant_dtor<'tcx>(
247252
param_env: ty::ParamEnv<'tcx>,
248253
ty: Ty<'tcx>,
249254
) -> SmallVec<[Ty<'tcx>; 4]> {
250-
let mut tys = extract_component_raw(tcx, param_env, ty);
255+
let mut tys = extract_component_raw(tcx, param_env, ty, &mut Default::default());
251256
let mut deduplicate = FxHashSet::default();
252257
tys.retain(|oty| deduplicate.insert(*oty));
253258
tys.into_iter().collect()

0 commit comments

Comments
 (0)