diff --git a/src/punctuated.rs b/src/punctuated.rs index 4d3496976c..7460cda62f 100644 --- a/src/punctuated.rs +++ b/src/punctuated.rs @@ -162,7 +162,13 @@ impl Punctuated { /// Panics if the sequence does not already have a trailing punctuation when /// this method is called. pub fn push_value(&mut self, value: T) { - assert!(self.empty_or_trailing()); + if !self.empty_or_trailing() { + panic!( + "Punctuated::push_value: Punctuated is not empty or \ + does not have a trailing punctuation" + ); + } + self.last = Some(Box::new(value)); } @@ -174,7 +180,10 @@ impl Punctuated { /// /// Panics if the sequence is empty or already has a trailing punctuation. pub fn push_punct(&mut self, punctuation: P) { - assert!(self.last.is_some()); + if !self.last.is_some() { + panic!("Punctuated::push_punct: Punctuated doesn't have any items"); + } + let last = self.last.take().unwrap(); self.inner.push((*last, punctuation)); } @@ -228,7 +237,9 @@ impl Punctuated { where P: Default, { - assert!(index <= self.len()); + if index > self.len() { + panic!("Punctuated::insert: index out of range"); + } if index == self.len() { self.push(value); @@ -454,7 +465,13 @@ impl FromIterator> for Punctuated { impl Extend> for Punctuated { fn extend>>(&mut self, i: I) { - assert!(self.empty_or_trailing()); + if !self.empty_or_trailing() { + panic!( + "Punctuated::extend: Punctuated is not empty or \ + does not have a trailing punctuation" + ); + } + let mut nomore = false; for pair in i { if nomore {