Skip to content

Commit

Permalink
Fix code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Sep 9, 2024
1 parent 0559ac3 commit a26ce37
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions noir_stdlib/src/collections/bounded_vec.nr
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ impl<T, let MaxLen: u32> BoundedVec<T, MaxLen> {
/// let v1: BoundedVec<Field, 3> = BoundedVec::new();
/// let v2 = BoundedVec::new();
///
/// // Ok! MaxLen is known from the type of foo's return value
/// // Ok! MaxLen is known from the type of `good`'s return value
/// v2
/// }
///
/// fn bad() {
/// // Error: Type annotation needed
/// // The compiller can't infer `MaxLen` from the following code:
/// let mut v3 = BoundedVec::new();
///
/// // Not Ok! We don't know if v3's MaxLen is at least 1, and the compiler often infers 0 by default.
/// v3.push(5);
/// }
/// ```
Expand Down Expand Up @@ -362,8 +362,9 @@ impl<T, let MaxLen: u32> BoundedVec<T, MaxLen> {
///
/// assert(two == 2);
/// assert(one == 1);
///
/// // error: cannot pop from an empty vector
/// // let _ = v.pop();
/// let _ = v.pop();
/// ```
pub fn pop(&mut self) -> T {
assert(self.len > 0);
Expand Down
12 changes: 6 additions & 6 deletions test_programs/noir_test_success/bounded_vec/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[test]
fn test_vec_new_foo() {
foo();
fn test_vec_new_good() {
good();
}

#[test(should_fail)]
Expand All @@ -9,19 +9,19 @@ fn test_vec_new_bad() {
}

// docs:start:new_example
fn foo() -> BoundedVec<Field, 10> {
fn good() -> BoundedVec<Field, 10> {
// Ok! MaxLen is specified with a type annotation
let v1: BoundedVec<Field, 3> = BoundedVec::new();
let v2 = BoundedVec::new();

// Ok! MaxLen is known from the type of foo's return value
// Ok! MaxLen is known from the type of `good`'s return value
v2
}

fn bad() {
// Error: Type annotation needed
// The compiller can't infer `MaxLen` from this code.
let mut v3 = BoundedVec::new();

// Not Ok! We don't know if v3's MaxLen is at least 1, and the compiler often infers 0 by default.
v3.push(5);
}
// docs:end:new_example
Expand Down

0 comments on commit a26ce37

Please sign in to comment.