Rollup merge of #68412 - GuillaumeGomez:clean-up-e0207, r=Dylan-DPC

Clean up E0207 explanation

r? @Dylan-DPC
This commit is contained in:
Yuki Okushi 2020-01-28 10:48:10 +09:00 committed by GitHub
commit dc33cd3500
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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