File tree Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -362,9 +362,9 @@ struct Foo1 { x: &bool }
362362 // ^ expected lifetime parameter
363363struct Foo2<'a> { x: &'a bool } // correct
364364
365- impl Foo2 { ... }
365+ impl Foo2 {}
366366 // ^ expected lifetime parameter
367- impl<'a> Foo2<'a> { ... } // correct
367+ impl<'a> Foo2<'a> {} // correct
368368
369369struct Bar1 { x: Foo2 }
370370 // ^^^^ expected lifetime parameter
@@ -777,21 +777,32 @@ struct Foo<'a> {
777777}
778778```
779779
780- Implementations need their own lifetime declarations:
780+ Impl blocks declare lifetime parameters separately. You need to add lifetime
781+ parameters to an impl block if you're implementing a type that has a lifetime
782+ parameter of its own.
783+ For example:
781784
782- ```
783- // error, undeclared lifetime
785+ ```compile_fail,E0261
786+ // error, use of undeclared lifetime name `'a`
784787impl Foo<'a> {
785- ...
788+ fn foo<'a>(x: &'a str) {}
789+ }
790+
791+ struct Foo<'a> {
792+ x: &'a str,
786793}
787794```
788795
789- Which are declared like this:
796+ This is fixed by declaring impl block like this:
790797
791798```
792799// correct
793800impl<'a> Foo<'a> {
794- ...
801+ fn foo(x: &'a str) {}
802+ }
803+
804+ struct Foo<'a> {
805+ x: &'a str,
795806}
796807```
797808"## ,
You can’t perform that action at this time.
0 commit comments