File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
src/doc/unstable-book/src/language-features Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -6,5 +6,42 @@ The tracking issue for this feature is: [#29628]
6
6
7
7
------------------------
8
8
9
+ The ` on_unimplemented ` feature provides the ` #[rustc_on_unimplemented] `
10
+ attribute, which allows trait definitions to add specialized notes to error
11
+ messages when an implementation was expected but not found.
9
12
13
+ For example:
14
+
15
+ ``` rust,compile_fail
16
+ #![feature(on_unimplemented)]
17
+
18
+ #[rustc_on_unimplemented="a collection of type `{Self}` cannot be built from an \
19
+ iterator over elements of type `{A}`"]
20
+ trait MyIterator<A> {
21
+ fn next(&mut self) -> A;
22
+ }
23
+
24
+ fn iterate_chars<I: MyIterator<char>>(i: I) {
25
+ // ...
26
+ }
27
+
28
+ fn main() {
29
+ iterate_chars(&[1, 2, 3][..]);
30
+ }
31
+ ```
32
+
33
+ When the user compiles this, they will see the following;
34
+
35
+ ``` txt
36
+ error[E0277]: the trait bound `&[{integer}]: MyIterator<char>` is not satisfied
37
+ --> <anon>:14:5
38
+ |
39
+ 14 | iterate_chars(&[1, 2, 3][..]);
40
+ | ^^^^^^^^^^^^^ the trait `MyIterator<char>` is not implemented for `&[{integer}]`
41
+ |
42
+ = note: a collection of type `&[{integer}]` cannot be built from an iterator over elements of type `char`
43
+ = note: required by `iterate_chars`
44
+
45
+ error: aborting due to previous error
46
+ ```
10
47
You can’t perform that action at this time.
0 commit comments