Skip to content

Commit 7c31609

Browse files
committed
Deprecation of str::slice_uncheked(_mut)
1 parent 773ce53 commit 7c31609

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

src/liballoc/str.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,11 @@ impl str {
266266
let mut result = String::new();
267267
let mut last_end = 0;
268268
for (start, part) in self.match_indices(from) {
269-
result.push_str(unsafe { self.slice_unchecked(last_end, start) });
269+
result.push_str(unsafe { self.get_unchecked(last_end..start) });
270270
result.push_str(to);
271271
last_end = start + part.len();
272272
}
273-
result.push_str(unsafe { self.slice_unchecked(last_end, self.len()) });
273+
result.push_str(unsafe { self.get_unchecked(last_end..self.len()) });
274274
result
275275
}
276276

@@ -307,11 +307,11 @@ impl str {
307307
let mut result = String::with_capacity(32);
308308
let mut last_end = 0;
309309
for (start, part) in self.match_indices(pat).take(count) {
310-
result.push_str(unsafe { self.slice_unchecked(last_end, start) });
310+
result.push_str(unsafe { self.get_unchecked(last_end..start) });
311311
result.push_str(to);
312312
last_end = start + part.len();
313313
}
314-
result.push_str(unsafe { self.slice_unchecked(last_end, self.len()) });
314+
result.push_str(unsafe { self.get_unchecked(last_end..self.len()) });
315315
result
316316
}
317317

src/liballoc/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ impl String {
12221222

12231223
while idx < len {
12241224
let ch = unsafe {
1225-
self.slice_unchecked(idx, len).chars().next().unwrap()
1225+
self.get_unchecked(idx..len).chars().next().unwrap()
12261226
};
12271227
let ch_len = ch.len_utf8();
12281228

src/libcore/str/mod.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ impl<'a, P: Pattern<'a>> SplitInternal<'a, P> {
10551055
if !self.finished && (self.allow_trailing_empty || self.end - self.start > 0) {
10561056
self.finished = true;
10571057
unsafe {
1058-
let string = self.matcher.haystack().slice_unchecked(self.start, self.end);
1058+
let string = self.matcher.haystack().get_unchecked(self.start..self.end);
10591059
Some(string)
10601060
}
10611061
} else {
@@ -1070,7 +1070,7 @@ impl<'a, P: Pattern<'a>> SplitInternal<'a, P> {
10701070
let haystack = self.matcher.haystack();
10711071
match self.matcher.next_match() {
10721072
Some((a, b)) => unsafe {
1073-
let elt = haystack.slice_unchecked(self.start, a);
1073+
let elt = haystack.get_unchecked(self.start..a);
10741074
self.start = b;
10751075
Some(elt)
10761076
},
@@ -1095,13 +1095,13 @@ impl<'a, P: Pattern<'a>> SplitInternal<'a, P> {
10951095
let haystack = self.matcher.haystack();
10961096
match self.matcher.next_match_back() {
10971097
Some((a, b)) => unsafe {
1098-
let elt = haystack.slice_unchecked(b, self.end);
1098+
let elt = haystack.get_unchecked(b..self.end);
10991099
self.end = a;
11001100
Some(elt)
11011101
},
11021102
None => unsafe {
11031103
self.finished = true;
1104-
Some(haystack.slice_unchecked(self.start, self.end))
1104+
Some(haystack.get_unchecked(self.start..self.end))
11051105
},
11061106
}
11071107
}
@@ -1222,7 +1222,7 @@ impl<'a, P: Pattern<'a>> MatchIndicesInternal<'a, P> {
12221222
#[inline]
12231223
fn next(&mut self) -> Option<(usize, &'a str)> {
12241224
self.0.next_match().map(|(start, end)| unsafe {
1225-
(start, self.0.haystack().slice_unchecked(start, end))
1225+
(start, self.0.haystack().get_unchecked(start..end))
12261226
})
12271227
}
12281228

@@ -1231,7 +1231,7 @@ impl<'a, P: Pattern<'a>> MatchIndicesInternal<'a, P> {
12311231
where P::Searcher: ReverseSearcher<'a>
12321232
{
12331233
self.0.next_match_back().map(|(start, end)| unsafe {
1234-
(start, self.0.haystack().slice_unchecked(start, end))
1234+
(start, self.0.haystack().get_unchecked(start..end))
12351235
})
12361236
}
12371237
}
@@ -1274,7 +1274,7 @@ impl<'a, P: Pattern<'a>> MatchesInternal<'a, P> {
12741274
fn next(&mut self) -> Option<&'a str> {
12751275
self.0.next_match().map(|(a, b)| unsafe {
12761276
// Indices are known to be on utf8 boundaries
1277-
self.0.haystack().slice_unchecked(a, b)
1277+
self.0.haystack().get_unchecked(a..b)
12781278
})
12791279
}
12801280

@@ -1284,7 +1284,7 @@ impl<'a, P: Pattern<'a>> MatchesInternal<'a, P> {
12841284
{
12851285
self.0.next_match_back().map(|(a, b)| unsafe {
12861286
// Indices are known to be on utf8 boundaries
1287-
self.0.haystack().slice_unchecked(a, b)
1287+
self.0.haystack().get_unchecked(a..b)
12881288
})
12891289
}
12901290
}
@@ -2453,6 +2453,7 @@ impl str {
24532453
/// }
24542454
/// ```
24552455
#[stable(feature = "rust1", since = "1.0.0")]
2456+
#[rustc_deprecated(since = "1.28.0", reason = "duplicates `get_unchecked`")]
24562457
#[inline]
24572458
pub unsafe fn slice_unchecked(&self, begin: usize, end: usize) -> &str {
24582459
(begin..end).get_unchecked(self)
@@ -2483,6 +2484,7 @@ impl str {
24832484
/// * `begin` and `end` must be byte positions within the string slice.
24842485
/// * `begin` and `end` must lie on UTF-8 sequence boundaries.
24852486
#[stable(feature = "str_slice_mut", since = "1.5.0")]
2487+
#[rustc_deprecated(since = "1.28.0", reason = "duplicates `get_unchecked`")]
24862488
#[inline]
24872489
pub unsafe fn slice_mut_unchecked(&mut self, begin: usize, end: usize) -> &mut str {
24882490
(begin..end).get_unchecked_mut(self)
@@ -2524,8 +2526,8 @@ impl str {
25242526
// is_char_boundary checks that the index is in [0, .len()]
25252527
if self.is_char_boundary(mid) {
25262528
unsafe {
2527-
(self.slice_unchecked(0, mid),
2528-
self.slice_unchecked(mid, self.len()))
2529+
(self.get_unchecked(0..mid),
2530+
self.get_unchecked(mid..self.len()))
25292531
}
25302532
} else {
25312533
slice_error_fail(self, 0, mid)
@@ -3652,7 +3654,7 @@ impl str {
36523654
}
36533655
unsafe {
36543656
// Searcher is known to return valid indices
3655-
self.slice_unchecked(i, j)
3657+
self.get_unchecked(i..j)
36563658
}
36573659
}
36583660

@@ -3691,7 +3693,7 @@ impl str {
36913693
}
36923694
unsafe {
36933695
// Searcher is known to return valid indices
3694-
self.slice_unchecked(i, self.len())
3696+
self.get_unchecked(i..self.len())
36953697
}
36963698
}
36973699

@@ -3738,7 +3740,7 @@ impl str {
37383740
}
37393741
unsafe {
37403742
// Searcher is known to return valid indices
3741-
self.slice_unchecked(0, j)
3743+
self.get_unchecked(0..j)
37423744
}
37433745
}
37443746

src/libcore/str/pattern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> {
354354
#[inline]
355355
fn next_back(&mut self) -> SearchStep {
356356
let old_finger = self.finger_back;
357-
let slice = unsafe { self.haystack.slice_unchecked(self.finger, old_finger) };
357+
let slice = unsafe { self.haystack.get_unchecked(self.finger..old_finger) };
358358
let mut iter = slice.chars();
359359
let old_len = iter.iter.len();
360360
if let Some(ch) = iter.next_back() {

0 commit comments

Comments
 (0)