@@ -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`" ]
23162315impl < 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`" ]
23292327impl < 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+ ) ]
23802390pub 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