Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,8 +1129,6 @@ impl String {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn insert(&mut self, idx: usize, ch: char) {
let len = self.len();
assert!(idx <= len);
assert!(self.is_char_boundary(idx));
let mut bits = [0; 4];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's redundant but it also affects the panic the users sees. The one below is the same, the last one is truly redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My personal opinion is that in this case, if we wanted a more verbose user error, we should do something like slice_error_fail from libstd/str.rs. Otherwise, it's just an assertion that adds more checks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that sounds fair

let bits = ch.encode_utf8(&mut bits).as_bytes();
Expand Down Expand Up @@ -1184,7 +1182,6 @@ impl String {
reason = "recent addition",
issue = "35553")]
pub fn insert_str(&mut self, idx: usize, string: &str) {
assert!(idx <= self.len());
assert!(self.is_char_boundary(idx));

unsafe {
Expand Down Expand Up @@ -1288,7 +1285,6 @@ impl String {
#[unstable(feature = "string_split_off", issue = "38080")]
pub fn split_off(&mut self, mid: usize) -> String {
assert!(self.is_char_boundary(mid));
assert!(mid <= self.len());
let other = self.vec.split_off(mid);
unsafe { String::from_utf8_unchecked(other) }
}
Expand Down