Skip to content

Commit

Permalink
Add support for mutating tuples.
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbolliger committed Jun 25, 2021
1 parent efcdb65 commit d90a314
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions stainless_extraction/src/expr/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ impl<'a, 'l, 'tcx> BodyExtractor<'a, 'l, 'tcx> {
)
.into()
}
TyKind::Tuple(substs) => {
let lhs = self.extract_expr(lhs);
f.FieldAssignment(
self.synth().tuple_select(substs.len(), lhs, name.index()),
self.synth().mut_cell_value_id(),
value,
)
.into()
}
ref t => self.unsupported_expr(
lhs.span,
format!("Cannot extract assignment to type {:?}", t),
Expand Down
1 change: 1 addition & 0 deletions stainless_frontend/tests/extraction_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ define_tests!(
pass: mut_ref_immut_borrow,
pass: mut_ref_tuple,
pass: mut_return,
pass: mut_tuple,
pass: nested_spec,
pass: nested_spec_impl,
pass: panic_type,
Expand Down
8 changes: 8 additions & 0 deletions stainless_frontend/tests/pass/mut_tuple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extern crate stainless;

pub fn main() {
let mut x = (123, false);
let y = x;
x.1 = true;
assert!(!y.1 && x.1)
}

0 comments on commit d90a314

Please sign in to comment.