@@ -2383,7 +2383,6 @@ impl [u8] {
23832383}
23842384
23852385#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2386- #[ rustc_on_unimplemented = "slice indices are of type `usize` or ranges of `usize`" ]
23872386impl < T , I > ops:: Index < I > for [ T ]
23882387 where I : SliceIndex < [ T ] >
23892388{
@@ -2396,7 +2395,6 @@ impl<T, I> ops::Index<I> for [T]
23962395}
23972396
23982397#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2399- #[ rustc_on_unimplemented = "slice indices are of type `usize` or ranges of `usize`" ]
24002398impl < T , I > ops:: IndexMut < I > for [ T ]
24012399 where I : SliceIndex < [ T ] >
24022400{
@@ -2447,7 +2445,19 @@ mod private_slice_index {
24472445
24482446/// A helper trait used for indexing operations.
24492447#[ stable( feature = "slice_get_slice" , since = "1.28.0" ) ]
2450- #[ rustc_on_unimplemented = "slice indices are of type `usize` or ranges of `usize`" ]
2448+ #[ rustc_on_unimplemented(
2449+ on(
2450+ T = "str" ,
2451+ label = "string indices are ranges of `usize`" ,
2452+ ) ,
2453+ on(
2454+ all( any( T = "str" , T = "&str" , T = "std::string::String" ) , _Self="{integer}" ) ,
2455+ note="you can use `.chars().nth()` or `.bytes().nth()`
2456+ see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
2457+ ) ,
2458+ message = "the type `{T}` cannot be indexed by `{Self}`" ,
2459+ label = "slice indices are of type `usize` or ranges of `usize`" ,
2460+ ) ]
24512461pub trait SliceIndex < T : ?Sized > : private_slice_index:: Sealed {
24522462 /// The output type returned by methods.
24532463 #[ stable( feature = "slice_get_slice" , since = "1.28.0" ) ]
0 commit comments