Fix changes for E0106, E0261
Replaced impl block dock with suggested one and made sure that blocks compile.
This commit is contained in:
parent
c738e6042d
commit
adadefd874
1 changed files with 19 additions and 8 deletions
|
|
@ -362,9 +362,9 @@ struct Foo1 { x: &bool }
|
|||
// ^ expected lifetime parameter
|
||||
struct Foo2<'a> { x: &'a bool } // correct
|
||||
|
||||
impl Foo2 { ... }
|
||||
impl Foo2 {}
|
||||
// ^ expected lifetime parameter
|
||||
impl<'a> Foo2<'a> { ... } // correct
|
||||
impl<'a> Foo2<'a> {} // correct
|
||||
|
||||
struct Bar1 { x: Foo2 }
|
||||
// ^^^^ expected lifetime parameter
|
||||
|
|
@ -777,21 +777,32 @@ struct Foo<'a> {
|
|||
}
|
||||
```
|
||||
|
||||
Implementations need their own lifetime declarations:
|
||||
Impl blocks declare lifetime parameters separately. You need to add lifetime
|
||||
parameters to an impl block if you're implementing a type that has a lifetime
|
||||
parameter of its own.
|
||||
For example:
|
||||
|
||||
```
|
||||
// error, undeclared lifetime
|
||||
```compile_fail,E0261
|
||||
// error, use of undeclared lifetime name `'a`
|
||||
impl Foo<'a> {
|
||||
...
|
||||
fn foo<'a>(x: &'a str) {}
|
||||
}
|
||||
|
||||
struct Foo<'a> {
|
||||
x: &'a str,
|
||||
}
|
||||
```
|
||||
|
||||
Which are declared like this:
|
||||
This is fixed by declaring impl block like this:
|
||||
|
||||
```
|
||||
// correct
|
||||
impl<'a> Foo<'a> {
|
||||
...
|
||||
fn foo(x: &'a str) {}
|
||||
}
|
||||
|
||||
struct Foo<'a> {
|
||||
x: &'a str,
|
||||
}
|
||||
```
|
||||
"##,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue