Clean up E0207 explanation
This commit is contained in:
parent
bf84eb538f
commit
0f5ed4d2cd
@ -1,3 +1,19 @@
|
||||
A type or lifetime parameter that is specified for `impl` is not constrained.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0207
|
||||
struct Foo;
|
||||
|
||||
impl<T: Default> Foo {
|
||||
// error: the type parameter `T` is not constrained by the impl trait, self
|
||||
// type, or predicates [E0207]
|
||||
fn get(&self) -> T {
|
||||
<T as Default>::default()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Any type parameter or lifetime parameter of an `impl` must meet at least one of
|
||||
the following criteria:
|
||||
|
||||
@ -10,19 +26,7 @@ the following criteria:
|
||||
### Error example 1
|
||||
|
||||
Suppose we have a struct `Foo` and we would like to define some methods for it.
|
||||
The following definition leads to a compiler error:
|
||||
|
||||
```compile_fail,E0207
|
||||
struct Foo;
|
||||
|
||||
impl<T: Default> Foo {
|
||||
// error: the type parameter `T` is not constrained by the impl trait, self
|
||||
// type, or predicates [E0207]
|
||||
fn get(&self) -> T {
|
||||
<T as Default>::default()
|
||||
}
|
||||
}
|
||||
```
|
||||
The previous code example has a definition which leads to a compiler error:
|
||||
|
||||
The problem is that the parameter `T` does not appear in the implementing type
|
||||
(`Foo`) of the impl. In this case, we can fix the error by moving the type
|
||||
|
Loading…
x
Reference in New Issue
Block a user