From a26ce374eaaa59970d812ebd12c875d2bf1c23b5 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Mon, 9 Sep 2024 12:45:03 -0300 Subject: [PATCH] Fix code examples --- noir_stdlib/src/collections/bounded_vec.nr | 9 +++++---- .../noir_test_success/bounded_vec/src/main.nr | 12 ++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/noir_stdlib/src/collections/bounded_vec.nr b/noir_stdlib/src/collections/bounded_vec.nr index f95794411b1..fede1b17c07 100644 --- a/noir_stdlib/src/collections/bounded_vec.nr +++ b/noir_stdlib/src/collections/bounded_vec.nr @@ -50,14 +50,14 @@ impl BoundedVec { /// let v1: BoundedVec = 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); /// } /// ``` @@ -362,8 +362,9 @@ impl BoundedVec { /// /// 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); diff --git a/test_programs/noir_test_success/bounded_vec/src/main.nr b/test_programs/noir_test_success/bounded_vec/src/main.nr index e5aa5f88a94..7b3e63df072 100644 --- a/test_programs/noir_test_success/bounded_vec/src/main.nr +++ b/test_programs/noir_test_success/bounded_vec/src/main.nr @@ -1,6 +1,6 @@ #[test] -fn test_vec_new_foo() { - foo(); +fn test_vec_new_good() { + good(); } #[test(should_fail)] @@ -9,19 +9,19 @@ fn test_vec_new_bad() { } // docs:start:new_example -fn foo() -> BoundedVec { +fn good() -> BoundedVec { // Ok! MaxLen is specified with a type annotation let v1: BoundedVec = 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