]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0404.md
Merge commit 'f2cdd4a78d89c009342197cf5844a21f8aa813df' into sync_cg_clif-2022-04-22
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0404.md
1 A type that is not a trait was used in a trait position, such as a bound
2 or `impl`.
3
4 Erroneous code example:
5
6 ```compile_fail,E0404
7 struct Foo;
8 struct Bar;
9
10 impl Foo for Bar {} // error: `Foo` is not a trait
11 fn baz<T: Foo>(t: T) {} // error: `Foo` is not a trait
12 ```
13
14 Another erroneous code example:
15
16 ```compile_fail,E0404
17 type Foo = Iterator<Item=String>;
18
19 fn bar<T: Foo>(t: T) {} // error: `Foo` is a type alias
20 ```
21
22 Please verify that the trait's name was not misspelled or that the right
23 identifier was used. Example:
24
25 ```
26 trait Foo {
27     // some functions
28 }
29 struct Bar;
30
31 impl Foo for Bar { // ok!
32     // functions implementation
33 }
34
35 fn baz<T: Foo>(t: T) {} // ok!
36 ```
37
38 Alternatively, you could introduce a new trait with your desired restrictions
39 as a super trait:
40
41 ```
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>;
55
56 fn bar<T: Foo>(t: T) {} // ok!
57 ```