Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
aca631f
Increase visibility of `join_path` and `split_paths`
tgross35 Jan 8, 2024
0de3677
Fix typo
joshtriplett Feb 11, 2024
75a4fa1
Suggest moving if non-found macro_rules! is defined later
chenyukang Feb 15, 2024
5d59d0c
have `String` use `SliceIndex` impls from `str`
pitaj Jan 24, 2024
11f9489
Changing some attributes to only_local.
surechen Feb 28, 2024
75e15f7
Deeply normalize obligations in refining_impl_trait
compiler-errors Feb 28, 2024
5512945
Implement unwind safety for Condvar
ecton Feb 28, 2024
3fbdec4
Add a comment about how `IntoDiagnostic` should be impl'd.
nnethercote Feb 27, 2024
199be46
Refactor `DiagCtxtInner::flush_delayed`.
nnethercote Feb 27, 2024
9dfe5ef
Fix typo in `rustc_passes/messages.ftl`
sisungo Feb 29, 2024
9c6a076
document potential memory leak in unbounded channel
ibraheemdev Feb 29, 2024
1850ba7
Remove unused diagnostic struct
mu001999 Feb 29, 2024
7c9fa95
fix typos
ibraheemdev Feb 29, 2024
da37c8f
Fix tests that are affected by this change
sisungo Feb 29, 2024
ad4c932
Restore the standard library review rotation to its former glory
Amanieu Feb 28, 2024
2978c98
Rollup merge of #119748 - tgross35:suggest-path-split, r=Amanieu
jhpratt Feb 29, 2024
7b29e65
Rollup merge of #120291 - pitaj:string-sliceindex, r=Amanieu
jhpratt Feb 29, 2024
032f19d
Rollup merge of #121130 - chenyukang:yukang-fix-121061-macro-later, r…
jhpratt Feb 29, 2024
cecc2a4
Rollup merge of #121723 - nnethercote:two-diagnostic-things, r=oli-obk
jhpratt Feb 29, 2024
4010270
Rollup merge of #121740 - surechen:change_attribute_to_local_20240228…
jhpratt Feb 29, 2024
d9becfb
Rollup merge of #121745 - compiler-errors:refining-impl-trait-deeply-…
jhpratt Feb 29, 2024
ccb2cb8
Rollup merge of #121748 - Amanieu:restore-libs-rotation, r=Amanieu
jhpratt Feb 29, 2024
f0e5863
Rollup merge of #121768 - ecton:condvar-unwindsafe, r=m-ou-se
jhpratt Feb 29, 2024
3b15e6b
Rollup merge of #121777 - sisungo:master, r=oli-obk
jhpratt Feb 29, 2024
e392b48
Rollup merge of #121778 - ibraheemdev:patch-19, r=RalfJung
jhpratt Feb 29, 2024
f8b3fbc
Rollup merge of #121779 - mu001999:clean, r=Nilstrieb
jhpratt Feb 29, 2024
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
Prev Previous commit
Next Next commit
have String use SliceIndex impls from str
  • Loading branch information
pitaj committed Feb 27, 2024
commit 5d59d0c7d725fe259b652bb9e9d17e6cbe1919af
1 change: 1 addition & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
#![feature(set_ptr_value)]
#![feature(sized_type_properties)]
#![feature(slice_from_ptr_range)]
#![feature(slice_index_methods)]
#![feature(slice_ptr_get)]
#![feature(slice_ptr_len)]
#![feature(slice_range)]
Expand Down
102 changes: 14 additions & 88 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use core::ops::Add;
use core::ops::AddAssign;
#[cfg(not(no_global_oom_handling))]
use core::ops::Bound::{Excluded, Included, Unbounded};
use core::ops::{self, Index, IndexMut, Range, RangeBounds};
use core::ops::{self, Range, RangeBounds};
use core::ptr;
use core::slice;
use core::str::pattern::Pattern;
Expand Down Expand Up @@ -2433,100 +2433,26 @@ impl AddAssign<&str> for String {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl ops::Index<ops::Range<usize>> for String {
type Output = str;
impl<I> ops::Index<I> for String
where
I: slice::SliceIndex<str>,
{
type Output = I::Output;

#[inline]
fn index(&self, index: ops::Range<usize>) -> &str {
&self[..][index]
fn index(&self, index: I) -> &I::Output {
index.index(self.as_str())
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl ops::Index<ops::RangeTo<usize>> for String {
type Output = str;

#[inline]
fn index(&self, index: ops::RangeTo<usize>) -> &str {
&self[..][index]
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl ops::Index<ops::RangeFrom<usize>> for String {
type Output = str;

#[inline]
fn index(&self, index: ops::RangeFrom<usize>) -> &str {
&self[..][index]
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl ops::Index<ops::RangeFull> for String {
type Output = str;

#[inline]
fn index(&self, _index: ops::RangeFull) -> &str {
unsafe { str::from_utf8_unchecked(&self.vec) }
}
}
#[stable(feature = "inclusive_range", since = "1.26.0")]
impl ops::Index<ops::RangeInclusive<usize>> for String {
type Output = str;

#[inline]
fn index(&self, index: ops::RangeInclusive<usize>) -> &str {
Index::index(&**self, index)
}
}
#[stable(feature = "inclusive_range", since = "1.26.0")]
impl ops::Index<ops::RangeToInclusive<usize>> for String {
type Output = str;

#[inline]
fn index(&self, index: ops::RangeToInclusive<usize>) -> &str {
Index::index(&**self, index)
}
}

#[stable(feature = "derefmut_for_string", since = "1.3.0")]
impl ops::IndexMut<ops::Range<usize>> for String {
#[inline]
fn index_mut(&mut self, index: ops::Range<usize>) -> &mut str {
&mut self[..][index]
}
}
#[stable(feature = "derefmut_for_string", since = "1.3.0")]
impl ops::IndexMut<ops::RangeTo<usize>> for String {
#[inline]
fn index_mut(&mut self, index: ops::RangeTo<usize>) -> &mut str {
&mut self[..][index]
}
}
#[stable(feature = "derefmut_for_string", since = "1.3.0")]
impl ops::IndexMut<ops::RangeFrom<usize>> for String {
#[inline]
fn index_mut(&mut self, index: ops::RangeFrom<usize>) -> &mut str {
&mut self[..][index]
}
}
#[stable(feature = "derefmut_for_string", since = "1.3.0")]
impl ops::IndexMut<ops::RangeFull> for String {
#[inline]
fn index_mut(&mut self, _index: ops::RangeFull) -> &mut str {
unsafe { str::from_utf8_unchecked_mut(&mut *self.vec) }
}
}
#[stable(feature = "inclusive_range", since = "1.26.0")]
impl ops::IndexMut<ops::RangeInclusive<usize>> for String {
#[inline]
fn index_mut(&mut self, index: ops::RangeInclusive<usize>) -> &mut str {
IndexMut::index_mut(&mut **self, index)
}
}
#[stable(feature = "inclusive_range", since = "1.26.0")]
impl ops::IndexMut<ops::RangeToInclusive<usize>> for String {
impl<I> ops::IndexMut<I> for String
where
I: slice::SliceIndex<str>,
{
#[inline]
fn index_mut(&mut self, index: ops::RangeToInclusive<usize>) -> &mut str {
IndexMut::index_mut(&mut **self, index)
fn index_mut(&mut self, index: I) -> &mut I::Output {
index.index_mut(self.as_mut_str())
}
}

Expand Down