Skip to content

Commit

Permalink
fix panic for unsupported for loops
Browse files Browse the repository at this point in the history
reported as #387 (comment)
  • Loading branch information
utaal committed Aug 13, 2023
1 parent e6c567c commit 3b0f834
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions source/rust_verify/src/fn_call_to_vir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ pub(crate) fn fn_call_to_vir<'tcx>(
Some(RustItem::TryTraitBranch) => {
return err_span(expr.span, "Verus does not yet support the ? operator");
}
Some(RustItem::IntoIterFn) => {
return err_span(
expr.span,
"Verus does not yet support IntoIterator::into_iter and for loops, use a while loop instead",
);
}
_ => {}
}

Expand Down
4 changes: 4 additions & 0 deletions source/rust_verify/src/verus_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ pub(crate) enum RustItem {
IntIntrinsic(RustIntIntrinsicItem),
AllocGlobal,
TryTraitBranch,
IntoIterFn,
}

pub(crate) fn get_rust_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<RustItem> {
Expand Down Expand Up @@ -582,6 +583,9 @@ pub(crate) fn get_rust_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<Ru
if tcx.lang_items().branch_fn() == Some(def_id) {
return Some(RustItem::TryTraitBranch);
}
if tcx.lang_items().into_iter_fn() == Some(def_id) {
return Some(RustItem::IntoIterFn);
}

let rust_path = def_id_to_stable_rust_path(tcx, def_id);
let rust_path = rust_path.as_ref().map(|x| x.as_str());
Expand Down
9 changes: 9 additions & 0 deletions source/rust_verify_test/tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,3 +558,12 @@ test_verify_one_file! {
}
} => Err(err) => assert_vir_error_msg(err, "unrecognized verifier attribute")
}

test_verify_one_file! {
#[test] test_for_loop_387_discussioncomment_5683342 verus_code! {
struct T{}
fn f(v: Vec<T>) {
for t in v {}
}
} => Err(err) => assert_vir_error_msg(err, "Verus does not yet support IntoIterator::into_iter")
}

0 comments on commit 3b0f834

Please sign in to comment.