Skip to content

Commit

Permalink
Make str indexing generic on SliceIndex.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Hunt committed Jan 19, 2019
1 parent af73e64 commit c7d25a2
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 235 deletions.
15 changes: 0 additions & 15 deletions src/libcore/ops/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,6 @@
/// ```
#[lang = "index"]
#[rustc_on_unimplemented(
on(
_Self="&str",
note="you can use `.chars().nth()` or `.bytes().nth()`
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
),
on(
_Self="str",
note="you can use `.chars().nth()` or `.bytes().nth()`
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
),
on(
_Self="std::string::String",
note="you can use `.chars().nth()` or `.bytes().nth()`
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
),
message="the type `{Self}` cannot be indexed by `{Idx}`",
label="`{Self}` cannot be indexed by `{Idx}`",
)]
Expand Down
16 changes: 13 additions & 3 deletions src/libcore/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2312,7 +2312,6 @@ impl [u8] {
}

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

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

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

0 comments on commit c7d25a2

Please sign in to comment.