-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix slice with range encoding (#972)
Fixes #960 Issue is described there. Not sure if this is the correct way to do the error reporting? It would be really nice to just have a contract for `index` and `index_mut` and report the error as a precondition violation of those. E.g. I really don't want to hardcode the pledge required for `index_mut` by hand.
- Loading branch information
1 parent
b3310ec
commit c7a3614
Showing
4 changed files
with
82 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use prusti_contracts::*; | ||
|
||
|
||
#[requires(end <= slice.len())] | ||
fn foo(slice: &[i32], start: usize, end: usize) { | ||
let subslice = &slice[start..end]; //~ ERROR the range end may be smaller than the start when slicing | ||
} | ||
|
||
#[requires(start <= end)] | ||
fn bar(slice: &[i32], start: usize, end: usize) { | ||
let subslice = &slice[start..end]; //~ ERROR the range end value may be out of bounds when slicing | ||
} | ||
|
||
#[requires(end <= slice.len())] | ||
fn foo_mut(slice: &mut [i32], start: usize, end: usize) { | ||
let subslice = &mut slice[start..end]; //~ ERROR mutably slicing is not fully supported yet | ||
} | ||
|
||
#[requires(start <= end)] | ||
fn bar_mut(slice: &mut [i32], start: usize, end: usize) { | ||
let subslice = &mut slice[start..end]; //~ ERROR mutably slicing is not fully supported yet | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters