@@ -103,14 +103,13 @@ test "realloc" {
103103
104104/// Retrieves the element at the specified index from the vector.
105105///
106- /// If you try to access an index which isn’t in the Vec, it will panic.
107- ///
108106/// # Example
109107/// ```
110108/// let v = Vec::new()
111109/// v.push(3)
112110/// println(v[0]) // 3
113111/// ```
112+ /// @alert unsafe "Panic if index is out of bounds"
114113pub fn op_get [T ](self : Vec [T ], index : Int ) -> T {
115114 if index < 0 || index >= self .len {
116115 let len = self .len
@@ -123,14 +122,13 @@ pub fn op_get[T](self : Vec[T], index : Int) -> T {
123122
124123/// Sets the value of the element at the specified index.
125124///
126- /// If you try to access an index which isn’t in the Vec, it will panic.
127- ///
128125/// # Example
129126/// ```
130127/// let v = Vec::new()
131128/// v.push(3)
132129/// println(v[0]) // 3
133130/// ```
131+ /// @alert unsafe "Panic if index is out of bounds."
134132pub fn op_set [T ](self : Vec [T ], index : Int , value : T ) -> Unit {
135133 if index < 0 || index >= self .len {
136134 let len = self .len
@@ -237,13 +235,12 @@ test "pop" {
237235
238236/// Removes the last element from a vector and returns it.
239237///
240- /// Panics if the vector is empty.
241- ///
242238/// # Example
243239/// ```
244240/// let v = Vec::[1, 2, 3]
245241/// v.pop_exn() // 3
246242/// ```
243+ /// @alert unsafe "Panic if the vector is empty."
247244pub fn pop_exn [T ](self : Vec [T ]) -> T {
248245 if self .len == 0 {
249246 abort ("pop from an empty Vec" )
@@ -289,13 +286,13 @@ test "push" {
289286/// Removes the specified range from the vector and returns it.
290287///
291288/// This functions returns a vector range from `begin` to `end` `[begin, end)`
292- /// If you try to access an index which isn’t in the Vec, it will panic.
293289///
294290/// # Example
295291/// ```
296292/// let v = Vec::[3, 4, 5]
297293/// let vv = v.drain(1, 2) // vv = Vec::[4], v = Vec::[3, 5]
298294/// ```
295+ /// @alert unsafe "Panic if index is out of bounds."
299296pub fn drain [T ](self : Vec [T ], begin : Int , end : Int ) -> Vec [T ] {
300297 if begin < 0 || begin >= self .len || end < 0 || end > self .len || begin > end {
301298 let len = self .len
@@ -564,14 +561,13 @@ test "reverse" {
564561
565562/// Split the vector into two at the given index.
566563///
567- /// If you try to access an index which isn’t in the Vec, it will panic.
568- ///
569564/// # Example
570565/// ```
571566/// let v = Vec::[3, 4, 5]
572567/// let (v1, v2) = v.split_at(1)
573568/// ```
574569/// TODO: perf could be optimized
570+ /// @alert unsafe "Panic if index is out of bounds."
575571pub fn split_at [T ](self : Vec [T ], index : Int ) -> (Vec [T ], Vec [T ]) {
576572 if index < 0 || index >= self .len {
577573 let len = self .len
@@ -761,13 +757,12 @@ test "search" {
761757
762758/// Swap two elements in the vector.
763759///
764- /// If you try to access an index which isn’t in the Vec, it will panic.
765- ///
766760/// # Example
767761/// ```
768762/// let v = Vec::[3, 4, 5]
769763/// v.swap(1, 2)
770764/// ```
765+ /// @alert unsafe "Panic if index is out of bounds."
771766pub fn swap [T ](self : Vec [T ], i : Int , j : Int ) -> Unit {
772767 if i >= self .len || j >= self .len || i < 0 || j < 0 {
773768 let len = self .len
@@ -797,6 +792,7 @@ test "swap" {
797792/// let v = Vec::[3, 4, 5]
798793/// v.remove(1)
799794/// ```
795+ /// @alert unsafe "Panic if index is out of bounds."
800796pub fn remove [T ](self : Vec [T ], index : Int ) -> T {
801797 if index < 0 || index >= self .len {
802798 let len = self .len
@@ -849,6 +845,7 @@ test "retain" {
849845/// ```
850846/// Vec::[3, 4, 5].resize(1)
851847/// ```
848+ /// @alert unsafe "Panic if new length is negative."
852849pub fn resize [T ](self : Vec [T ], new_len : Int , f : T ) -> Unit {
853850 if new_len < 0 {
854851 abort ("negative new length" )
@@ -875,12 +872,11 @@ test "resize" {
875872
876873/// Inserts an element at a given index within the vector.
877874///
878- /// If you try to access an index which isn’t in the Vec, it will panic.
879- ///
880875/// # Example
881876/// ```
882877/// Vec::[3, 4, 5].insert(1, 6)
883878/// ```
879+ /// @alert unsafe "Panic if index is out of bounds."
884880pub fn insert [T ](self : Vec [T ], index : Int , value : T ) -> Unit {
885881 if index < 0 || index > self .len {
886882 let len = self .len
0 commit comments