diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 4bc52e82f9be1..dd5144b1568fb 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -362,6 +362,10 @@ struct Foo1 { x: &bool } // ^ expected lifetime parameter struct Foo2<'a> { x: &'a bool } // correct +impl Foo2 {} + // ^ expected lifetime parameter +impl<'a> Foo2<'a> {} // correct + struct Bar1 { x: Foo2 } // ^^^^ expected lifetime parameter struct Bar2<'a> { x: Foo2<'a> } // correct @@ -768,6 +772,35 @@ These can be fixed by declaring lifetime parameters: ``` fn foo<'a>(x: &'a str) {} +struct Foo<'a> { + x: &'a str, +} +``` + +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: + +```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, +} +``` + +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, }