File tree Expand file tree Collapse file tree 1 file changed +17
-13
lines changed
src/librustc_error_codes/error_codes Expand file tree Collapse file tree 1 file changed +17
-13
lines changed Original file line number Diff line number Diff line change
1
+ A type or lifetime parameter that is specified for ` impl ` is not constrained.
2
+
3
+ Erroneous code example:
4
+
5
+ ``` compile_fail,E0207
6
+ struct Foo;
7
+
8
+ impl<T: Default> Foo {
9
+ // error: the type parameter `T` is not constrained by the impl trait, self
10
+ // type, or predicates [E0207]
11
+ fn get(&self) -> T {
12
+ <T as Default>::default()
13
+ }
14
+ }
15
+ ```
16
+
1
17
Any type parameter or lifetime parameter of an ` impl ` must meet at least one of
2
18
the following criteria:
3
19
@@ -10,19 +26,7 @@ the following criteria:
10
26
### Error example 1
11
27
12
28
Suppose we have a struct ` Foo ` and we would like to define some methods for it.
13
- The following definition leads to a compiler error:
14
-
15
- ``` compile_fail,E0207
16
- struct Foo;
17
-
18
- impl<T: Default> Foo {
19
- // error: the type parameter `T` is not constrained by the impl trait, self
20
- // type, or predicates [E0207]
21
- fn get(&self) -> T {
22
- <T as Default>::default()
23
- }
24
- }
25
- ```
29
+ The previous code example has a definition which leads to a compiler error:
26
30
27
31
The problem is that the parameter ` T ` does not appear in the implementing type
28
32
(` Foo ` ) of the impl. In this case, we can fix the error by moving the type
You can’t perform that action at this time.
0 commit comments