Skip to content

Commit 251db3d

Browse files
committed
Fix borrows
1 parent c93c37b commit 251db3d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

creusot/src/backend/ty_inv.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,18 @@ fn build_inv_exp_struct<'tcx>(
175175
TyKind::Ref(_, ty, Mutability::Not) => {
176176
build_inv_exp(ctx, names, ident, *ty, param_env, destruct_adt)
177177
}
178-
TyKind::Ref(_, ty, Mutability::Mut) => {
179-
let e = build_inv_exp(ctx, names, ident, *ty, param_env, destruct_adt)?;
178+
TyKind::Ref(_, ty, Mutability::Mut) if destruct_adt => {
179+
// cannot inline in ADTs, or else we might be missing
180+
// `use prelude.Borrow`
181+
180182
// TODO include final value
181-
Some(Exp::Current(Box::new(e)))
183+
let deref = Exp::Current(Box::new(Exp::pure_var(ident)));
184+
let body = build_inv_exp(ctx, names, "a".into(), *ty, param_env, destruct_adt)?;
185+
Some(Exp::Let {
186+
pattern: Pattern::VarP("a".into()),
187+
arg: Box::new(deref),
188+
body: Box::new(body),
189+
})
182190
}
183191
TyKind::Tuple(tys) => {
184192
let fields: Vec<Ident> =
@@ -201,7 +209,7 @@ fn build_inv_exp_struct<'tcx>(
201209
TyKind::Adt(adt_def, subst) if destruct_adt => {
202210
build_inv_exp_adt(ctx, names, ident, param_env, *adt_def, subst)
203211
}
204-
TyKind::Adt(_, _) | TyKind::Param(_) => {
212+
TyKind::Ref(_, _, _) | TyKind::Adt(_, _) | TyKind::Param(_) => {
205213
let inv_fun = Exp::impure_qvar(names.ty_inv(ty));
206214
Some(inv_fun.app_to(Exp::pure_var(ident)))
207215
}

0 commit comments

Comments
 (0)