Skip to content

Commit 5e8a125

Browse files
authored
add no_unwind to vec index and vec len (#1613)
1 parent e36d808 commit 5e8a125

4 files changed

Lines changed: 25 additions & 4 deletions

File tree

source/rust_verify_test/tests/std.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,3 +573,19 @@ test_verify_one_file_with_options! {
573573
}
574574
} => Err(err) => assert_vir_error_msg(err, "cannot use function `crate::X::clone` which is ignored")
575575
}
576+
577+
test_verify_one_file! {
578+
#[test] vec_index_nounwind verus_code! {
579+
use vstd::*;
580+
581+
fn test(v: Vec<u64>)
582+
requires v.len() > 5,
583+
no_unwind
584+
{
585+
let x = v[0];
586+
let mut v = v;
587+
v[1] = 4;
588+
let l = v.len();
589+
}
590+
} => Ok(())
591+
}

source/vir/src/sst_to_air.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,13 +1683,13 @@ fn stm_to_stmts(ctx: &Ctx, state: &mut State, stm: &Stm) -> Result<Vec<Stmt>, Vi
16831683
UnwindAir::NoUnwind(ReasonForNoUnwind::Function) => error_with_label(
16841684
&stm.span,
16851685
"cannot show this call will not unwind, in function marked 'no_unwind'",
1686-
"this call might unwind",
1686+
format!("call to {:} might unwind", fun_as_friendly_rust_name(fun)),
16871687
),
16881688
UnwindAir::NoUnwind(ReasonForNoUnwind::OpenInvariant(span)) => {
16891689
error_with_label(
16901690
&stm.span,
16911691
"cannot show this call will not unwind",
1692-
"this call might unwind",
1692+
format!("call to {:} might unwind", fun_as_friendly_rust_name(fun)),
16931693
)
16941694
.secondary_label(span, "unwinding is not allowed in this invariant block")
16951695
}

source/vstd/std_specs/core.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::super::prelude::*;
22

3-
verus! {
3+
use verus as verus_;
4+
verus_! {
45

56
#[verifier::external_trait_specification]
67
pub trait ExIndex<Idx> where Idx: ?Sized {
@@ -216,6 +217,7 @@ pub fn index_set<T, Idx, E>(container: &mut T, index: Idx, val: E) where
216217
old(container).spec_index_set_requires(index),
217218
ensures
218219
old(container).spec_index_set_ensures(container, index, val),
220+
no_unwind
219221
{
220222
container[index] = val;
221223
}

source/vstd/std_specs/vec.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use core::clone::Clone;
77
use core::option::Option;
88
use core::option::Option::None;
99

10-
verus! {
10+
use verus as verus_;
11+
verus_! {
1112

1213
#[verifier::external_type_specification]
1314
#[verifier::external_body]
@@ -46,6 +47,7 @@ pub fn vec_index<T, A: Allocator>(vec: &Vec<T, A>, i: usize) -> (element: &T)
4647
i < vec.view().len(),
4748
ensures
4849
*element == vec.view().index(i as int),
50+
no_unwind
4951
{
5052
&vec[i]
5153
}
@@ -66,6 +68,7 @@ pub broadcast proof fn axiom_spec_len<A>(v: &Vec<A>)
6668
pub assume_specification<T, A: Allocator>[ Vec::<T, A>::len ](vec: &Vec<T, A>) -> usize
6769
returns
6870
spec_vec_len(vec),
71+
no_unwind
6972
;
7073

7174
////// Other functions

0 commit comments

Comments
 (0)