File tree Expand file tree Collapse file tree 1 file changed +20
-6
lines changed
compiler/rustc_error_codes/src/error_codes Expand file tree Collapse file tree 1 file changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -8,14 +8,15 @@ struct Foo;
88struct Bar;
99
1010impl Foo for Bar {} // error: `Foo` is not a trait
11+ fn baz<T: Foo>(t: T) {} // error: `Foo` is not a trait
1112```
1213
1314Another erroneous code example:
1415
1516``` compile_fail,E0404
16- struct Foo;
17+ type Foo = Iterator<Item=String> ;
1718
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
1920```
2021
2122Please verify that the trait's name was not misspelled or that the right
@@ -30,14 +31,27 @@ struct Bar;
3031impl Foo for Bar { // ok!
3132 // functions implementation
3233}
34+
35+ fn baz<T: Foo>(t: T) {} // ok!
3336```
3437
35- or:
38+ Alternatively, you could introduce a new trait with your desired restrictions
39+ as a super trait:
3640
3741```
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>;
4155
4256fn bar<T: Foo>(t: T) {} // ok!
4357```
You can’t perform that action at this time.
0 commit comments