Skip to content

Commit c7d25a2

Browse files
author
Alexis Hunt
committed
Make str indexing generic on SliceIndex.
1 parent af73e64 commit c7d25a2

13 files changed

+239
-235
lines changed

src/libcore/ops/index.rs

-15
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,6 @@
5151
/// ```
5252
#[lang = "index"]
5353
#[rustc_on_unimplemented(
54-
on(
55-
_Self="&str",
56-
note="you can use `.chars().nth()` or `.bytes().nth()`
57-
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
58-
),
59-
on(
60-
_Self="str",
61-
note="you can use `.chars().nth()` or `.bytes().nth()`
62-
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
63-
),
64-
on(
65-
_Self="std::string::String",
66-
note="you can use `.chars().nth()` or `.bytes().nth()`
67-
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
68-
),
6954
message="the type `{Self}` cannot be indexed by `{Idx}`",
7055
label="`{Self}` cannot be indexed by `{Idx}`",
7156
)]

src/libcore/slice/mod.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -2312,7 +2312,6 @@ impl [u8] {
23122312
}
23132313

23142314
#[stable(feature = "rust1", since = "1.0.0")]
2315-
#[rustc_on_unimplemented = "slice indices are of type `usize` or ranges of `usize`"]
23162315
impl<T, I> ops::Index<I> for [T]
23172316
where I: SliceIndex<[T]>
23182317
{
@@ -2325,7 +2324,6 @@ impl<T, I> ops::Index<I> for [T]
23252324
}
23262325

23272326
#[stable(feature = "rust1", since = "1.0.0")]
2328-
#[rustc_on_unimplemented = "slice indices are of type `usize` or ranges of `usize`"]
23292327
impl<T, I> ops::IndexMut<I> for [T]
23302328
where I: SliceIndex<[T]>
23312329
{
@@ -2376,7 +2374,19 @@ mod private_slice_index {
23762374

23772375
/// A helper trait used for indexing operations.
23782376
#[stable(feature = "slice_get_slice", since = "1.28.0")]
2379-
#[rustc_on_unimplemented = "slice indices are of type `usize` or ranges of `usize`"]
2377+
#[rustc_on_unimplemented(
2378+
on(
2379+
T = "str",
2380+
label = "string indices are ranges of `usize`",
2381+
),
2382+
on(
2383+
all(any(T = "str", T = "&str", T = "std::string::String"), _Self="{integer}"),
2384+
note="you can use `.chars().nth()` or `.bytes().nth()`
2385+
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
2386+
),
2387+
message = "the type `{T}` cannot be indexed by `{Self}`",
2388+
label = "slice indices are of type `usize` or ranges of `usize`",
2389+
)]
23802390
pub trait SliceIndex<T: ?Sized>: private_slice_index::Sealed {
23812391
/// The output type returned by methods.
23822392
#[stable(feature = "slice_get_slice", since = "1.28.0")]

0 commit comments

Comments
 (0)