Skip to content

Commit 0f5ed4d

Browse files
Clean up E0207 explanation
1 parent bf84eb5 commit 0f5ed4d

File tree

1 file changed

+17
-13
lines changed
  • src/librustc_error_codes/error_codes

1 file changed

+17
-13
lines changed

src/librustc_error_codes/error_codes/E0207.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
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+
117
Any type parameter or lifetime parameter of an `impl` must meet at least one of
218
the following criteria:
319

@@ -10,19 +26,7 @@ the following criteria:
1026
### Error example 1
1127

1228
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:
2630

2731
The problem is that the parameter `T` does not appear in the implementing type
2832
(`Foo`) of the impl. In this case, we can fix the error by moving the type

0 commit comments

Comments
 (0)