Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/refine/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ where
pred_args.push(field_term.clone());

if let Some(p) = field_type.as_pointer() {
if matches!(&p.elem.ty, rty::Type::Enum(e) if e.symbol == ety.symbol) {
if p.elem.ty.to_sort() == ty.to_sort() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Detect recursive cycles across generic instantiations

When a recursive enum permutes its type arguments, exact sort equality never identifies the recursive field. For example, enum E<T, U> { Value(T, U), Next(Box<E<U, T>>) } is valid Rust, but dropping E<i32, bool> recursively alternates between E<i32, bool> and E<bool, i32> here until Thrust overflows its stack. The previous symbol comparison stopped this recursion, so the recursion guard needs to track datatype cycles rather than only an identical instantiated sort.

Useful? React with 👍 / 👎.

// TODO: we need recursively defined drop_pred for the recursive ADTs!
tracing::warn!("skipping recursive variant");
continue;
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/fail/enum_nested_same_enum_mut_drop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@error-in-other-file: Unsat
//@compile-flags: -C debug-assertions=off

fn main() {
let mut slot: Option<i64> = None;
let o: Option<&mut Option<i64>> = Some(&mut slot);
if let Some(s) = o {
*s = Some(3);
}
match slot {
Some(y) => assert!(y == 4),
None => assert!(false),
}
}
14 changes: 14 additions & 0 deletions tests/ui/pass/enum_nested_same_enum_mut_drop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@check-pass
//@compile-flags: -C debug-assertions=off

fn main() {
let mut slot: Option<i64> = None;
let o: Option<&mut Option<i64>> = Some(&mut slot);
if let Some(s) = o {
*s = Some(3);
}
match slot {
Some(y) => assert!(y == 3),
None => assert!(false),
}
}
Loading