Inconsistencies between documentation and code implementation
YichiZhang0613 opened this issue · 2 comments
YichiZhang0613 commented
I found several inconsistencies between documentation and code implementation. The details can be found in the following code.
toml/crates/toml_edit/src/array.rs
I think the documentation should be Panics if index >= len
instead of Panics if index > len
.
/// # Panics
///
/// Panics if `index > len`.
pub fn insert<V: Into<Value>>(&mut self, index: usize, v: V) {
self.value_op(v.into(), true, |items, value| {
items.insert(index, Item::Value(value))
})
}
toml/crates/toml_edit/src/array.rs
I think the code should check whether index is out of bounds before directly used as &mut self.values[index]. This may cause unnecessary panics.
/// # Panics
///
/// Panics if `index >= len`.
pub fn replace_formatted(&mut self, index: usize, v: Value) -> Value {
match mem::replace(&mut self.values[index], Item::Value(v)) {
Item::Value(old_value) => old_value,
x => panic!("non-value item {:?} in an array", x),
}
}
epage commented
For the first, it is copied from Vec::insert
which we delegate to
For the second, the change and the intent behind it isn't clear.
epage commented
Without further information, it seems the documentation is correct and closing