summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_error_codes/src/error_codes/E0261.md
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_error_codes/src/error_codes/E0261.md')
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0261.md52
1 files changed, 52 insertions, 0 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0261.md b/compiler/rustc_error_codes/src/error_codes/E0261.md
new file mode 100644
index 000000000..e32684373
--- /dev/null
+++ b/compiler/rustc_error_codes/src/error_codes/E0261.md
@@ -0,0 +1,52 @@
+An undeclared lifetime was used.
+
+Erroneous code example:
+
+```compile_fail,E0261
+// error, use of undeclared lifetime name `'a`
+fn foo(x: &'a str) { }
+
+struct Foo {
+ // error, use of undeclared lifetime name `'a`
+ x: &'a str,
+}
+```
+
+These can be fixed by declaring lifetime parameters:
+
+```
+struct Foo<'a> {
+ x: &'a str,
+}
+
+fn 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
+struct Foo<'a> {
+ x: &'a str,
+}
+
+// error, use of undeclared lifetime name `'a`
+impl Foo<'a> {
+ fn foo<'a>(x: &'a str) {}
+}
+```
+
+This is fixed by declaring the impl block like this:
+
+```
+struct Foo<'a> {
+ x: &'a str,
+}
+
+// correct
+impl<'a> Foo<'a> {
+ fn foo(x: &'a str) {}
+}
+```