Skip to content

Commit

Permalink
Merge pull request #4926 from epage/unsafe
Browse files Browse the repository at this point in the history
fix(lex)!: Remove unsafe safe method
  • Loading branch information
epage authored May 19, 2023
2 parents 8507a1d + 3db3524 commit fd63feb
Showing 1 changed file with 0 additions and 42 deletions.
42 changes: 0 additions & 42 deletions clap_lex/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,39 +162,6 @@ pub trait OsStrExt: private::Sealed {
///
/// [`split_whitespace`]: str::split_whitespace
fn split<'s, 'n>(&'s self, needle: &'n str) -> Split<'s, 'n>;
/// Divide one string slice into two at an index.
///
/// The argument, `mid`, should be a byte offset from the start of the
/// string. It must also be on the boundary of a UTF-8 code point.
///
/// The two slices returned go from the start of the string slice to `mid`,
/// and from `mid` to the end of the string slice.
///
/// To get mutable string slices instead, see the [`split_at_mut`]
/// method.
///
/// [`split_at_mut`]: str::split_at_mut
///
/// # Panics
///
/// Panics if `mid` is not on a UTF-8 code point boundary, or if it is
/// past the end of the last code point of the string slice.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use clap_lex::OsStrExt as _;
/// let s = std::ffi::OsStr::new("Per Martin-Löf");
///
/// let (first, last) = s.split_at(3);
///
/// assert_eq!("Per", first);
/// assert_eq!(" Martin-Löf", last);
/// ```
#[deprecated(since = "4.1.0", note = "This is not sound for all `index`")]
fn split_at(&self, index: usize) -> (&OsStr, &OsStr);
/// Splits the string on the first occurrence of the specified delimiter and
/// returns prefix before delimiter and suffix after delimiter.
///
Expand Down Expand Up @@ -249,15 +216,6 @@ impl OsStrExt for OsStr {
}
}

fn split_at(&self, index: usize) -> (&OsStr, &OsStr) {
let bytes = to_bytes(self);
unsafe {
// BUG: This is unsafe and has been deprecated
let (first, second) = bytes.split_at(index);
(to_os_str_unchecked(first), to_os_str_unchecked(second))
}
}

fn split_once(&self, needle: &'_ str) -> Option<(&OsStr, &OsStr)> {
let start = self.find(needle)?;
let end = start + needle.len();
Expand Down

0 comments on commit fd63feb

Please sign in to comment.