File tree 1 file changed +20
-6
lines changed
compiler/rustc_error_codes/src/error_codes
1 file changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -8,14 +8,15 @@ struct Foo;
8
8
struct Bar;
9
9
10
10
impl Foo for Bar {} // error: `Foo` is not a trait
11
+ fn baz<T: Foo>(t: T) {} // error: `Foo` is not a trait
11
12
```
12
13
13
14
Another erroneous code example:
14
15
15
16
``` compile_fail,E0404
16
- struct Foo;
17
+ type Foo = Iterator<Item=String> ;
17
18
18
- fn bar<T: Foo>(t: T) {} // error: `Foo` is not a trait
19
+ fn bar<T: Foo>(t: T) {} // error: `Foo` is a type alias
19
20
```
20
21
21
22
Please verify that the trait's name was not misspelled or that the right
@@ -30,14 +31,27 @@ struct Bar;
30
31
impl Foo for Bar { // ok!
31
32
// functions implementation
32
33
}
34
+
35
+ fn baz<T: Foo>(t: T) {} // ok!
33
36
```
34
37
35
- or:
38
+ Alternatively, you could introduce a new trait with your desired restrictions
39
+ as a super trait:
36
40
37
41
```
38
- trait Foo {
39
- // some functions
40
- }
42
+ # trait Foo {}
43
+ # struct Bar;
44
+ # impl Foo for Bar {}
45
+ trait Qux: Foo {} // Anything that implements Qux also needs to implement Foo
46
+ fn baz<T: Qux>(t: T) {} // also ok!
47
+ ```
48
+
49
+ Finally, if you are on nightly and want to use a trait alias
50
+ instead of a type alias, you should use ` #![feature(trait_alias)] ` :
51
+
52
+ ```
53
+ #![feature(trait_alias)]
54
+ trait Foo = Iterator<Item=String>;
41
55
42
56
fn bar<T: Foo>(t: T) {} // ok!
43
57
```
You can’t perform that action at this time.
0 commit comments