about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorfolex <0xdxdy@gmail.com>2019-01-05 05:56:23 +0300
committerfolex <0xdxdy@gmail.com>2019-01-05 09:40:08 +0300
commitc120199116439827a89a0ac0f24f91f99dbed60f (patch)
tree5d07587b3fcaf418ea822b87fff1dd4d03840ed3 /src/libcore
parentbf6bb141bbc77bfb7d9bc79f2db6d986aafc01cc (diff)
Show suggestion to use .char().nth() and link to The Book on unimplemented Index trait
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/ops/index.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libcore/ops/index.rs b/src/libcore/ops/index.rs
index 4f55c68ecd4..6cfa36741d0 100644
--- a/src/libcore/ops/index.rs
+++ b/src/libcore/ops/index.rs
@@ -51,6 +51,21 @@
 /// ```
 #[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}`",
 )]
@@ -141,6 +156,21 @@ pub trait Index<Idx: ?Sized> {
 /// ```
 #[lang = "index_mut"]
 #[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 mutably indexed by `{Idx}`",
     label="`{Self}` cannot be mutably indexed by `{Idx}`",
 )]