E0261 Undeclared Lifetime Name Fix
Written November 27, 2026 · Tested with Rust 1.99.1 · 24 min read
- The error: a function using a lifetime it never declares
- First fix: declare the lifetime on the function
- A struct field: the declaration goes on the struct
- Impl blocks: the lifetime is declared on the impl, separately
Written November 27, 2026
Tested with Rust 1.99.1
What this guide is
E0261 is the error for a lifetime name that is used but never declared. A lifetime parameter works like any other parameter: writing 'a in a signature names a parameter, and that name has to be introduced in the angle brackets of the item that uses it — fn f<'a>(x: &'a str), struct Foo<'a>, impl<'a> Foo<'a>. Leave the declaration off and the name refers to nothing, so the compiler stops with E0261, use of undeclared lifetime name, at every place the name appears.
The repairs are two, and choosing between them is the real decision. Declare the lifetime on the item that uses it, when the item genuinely needs to talk about that lifetime — a struct holding a reference, a function tying its return value to a specific input. Or remove the name entirely, when the position is one where the elision rules already supply a lifetime: a plain &str parameter needs no name at all, and naming one you then have to declare is work for nothing. Two names never need declaring in the first place: 'static, which the language provides, and '_, the placeholder that asks for an inferred lifetime in the positions where inference is allowed. The sections below take the shapes in order: the plain function case, the struct case, impl blocks — where one of the compiler's two suggestions, applied alone, does not finish the job — trait definitions, multiple names, bounds, the elision removal, the names that never trigger this error, and the neighboring errors.
The error: a function using a lifetime it never declares
This function uses 'a in its only parameter and declares no lifetime at all:
fn f(x: &'a str) {}
fn main() {
f("hi");
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0261]: use of undeclared lifetime name `'a`
--> main.rs:1:10
|
1 | fn f(x: &'a str) {}
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
1 | fn f<'a>(x: &'a str) {}
| ++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0261`.
The diagnostic is short compared to most lifetime errors, because nothing about borrowing is wrong yet. The span underlines the name itself, labeled undeclared lifetime, and the help offers the whole repair: consider introducing lifetime 'a here, inserting <'a> after the function's name. There is no second span and no note about regions — the fault is purely in the declaration, and it is found before any borrow checking of the body begins.
First fix: declare the lifetime on the function
Following the help exactly repairs the program:
fn f<'a>(x: &'a str) -> usize {
x.len()
}
fn main() {
println!("{}", f("hi"));
}
$ rustc --edition 2021 main.rs -o main.bin
$ ./main.bin
2
The program prints 2 and exits with status 0. The declaration is what makes the name usable everywhere in the signature at once — parameters, return type, and bounds. A name used twice in one signature is still one declaration, but, as a later section shows, an undeclared name used twice is two errors, not one: the compiler charges each use separately until the declaration exists.
A struct field: the declaration goes on the struct
A struct that stores a reference has the same fault in its field type, and the help points at the struct's name, not the field:
struct Foo {
x: &'a str,
}
fn main() {
let f = Foo { x: "hi" };
println!("{}", f.x);
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0261]: use of undeclared lifetime name `'a`
--> main.rs:2:9
|
2 | x: &'a str,
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
1 | struct Foo<'a> {
| ++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0261`.
With the parameter declared on the struct, the original body compiles unchanged, and every use of the struct from then on carries the lifetime with it:
struct Foo<'a> {
x: &'a str,
}
fn main() {
let f = Foo { x: "hi" };
println!("{}", f.x);
}
$ rustc --edition 2021 main.rs -o main.bin
$ ./main.bin
hi
The program prints hi and exits with status 0. Unlike a function, a struct cannot fall back on elision for a stored reference — there is no signature for the elision rules to work on — so for struct fields the declaration is not one repair among two; it is the repair. An enum is in the same position. A variant holding &'a str in an enum with no parameter fails with the same code, the span on the variant's field, and help offering enum E<'a>; with the parameter declared, the enum compiles and matches as usual.
Impl blocks: the lifetime is declared on the impl, separately
Impl blocks are where this error doubles. This program declares 'a on the struct, then uses it in the impl header and in a method's return type, declaring it in neither place:
struct Foo<'a> {
x: &'a str,
}
impl Foo<'a> {
fn get(&self) -> &'a str {
self.x
}
}
fn main() {
let f = Foo { x: "hi" };
println!("{}", f.get());
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0261]: use of undeclared lifetime name `'a`
--> main.rs:5:10
|
5 | impl Foo<'a> {
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
5 | impl<'a> Foo<'a> {
| ++++
error[E0261]: use of undeclared lifetime name `'a`
--> main.rs:6:23
|
6 | fn get(&self) -> &'a str {
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
6 | fn get<'a>(&self) -> &'a str {
| ++++
help: consider introducing lifetime `'a` here
|
5 | impl<'a> Foo<'a> {
| ++++
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0261`.
Two errors, one per item that uses the name without declaring it: the impl header, and the method. The second error carries two help blocks, and they are not interchangeable. One introduces the lifetime on the method, fn get<'a>; the other introduces it on the impl, impl<'a> Foo<'a>. Applying the method-level suggestion alone does not repair the program:
struct Foo<'a> {
x: &'a str,
}
impl Foo<'a> {
fn get<'a>(&self) -> &'a str {
self.x
}
}
fn main() {
let f = Foo { x: "hi" };
println!("{}", f.get());
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0261]: use of undeclared lifetime name `'a`
--> main.rs:5:10
|
5 | impl Foo<'a> {
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
5 | impl<'a> Foo<'a> {
| ++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0261`.
The method's own error is gone — its declaration is real, and it shadows nothing and conflicts with nothing — but the impl header still names a lifetime the impl never introduced, so one E0261 remains. The impl-level suggestion is the one that finishes the job, because a method uses the impl's parameters the way it uses its own: once the impl declares 'a, the method's return type names the impl's parameter and needs no declaration of its own:
struct Foo<'a> {
x: &'a str,
}
impl<'a> Foo<'a> {
fn get(&self) -> &'a str {
self.x
}
}
fn main() {
let f = Foo { x: "hi" };
println!("{}", f.get());
}
$ rustc --edition 2021 main.rs -o main.bin
$ ./main.bin
hi
The program prints hi and exits with status 0. The rule for impl blocks: a lifetime parameter on the type being implemented is declared on the impl, in its own angle brackets before the type — impl<'a> Foo<'a> — and that one declaration covers the header and every method in the block. Declaring the lifetime on the struct did none of this work; each item that names a lifetime introduces it for itself.
A method inside an impl of a type with no lifetime parameter is simpler, and behaves like a plain function. This method uses 'a and its help offers both the method and the impl as introduction points:
struct Foo;
impl Foo {
fn f(x: &'a str) {}
}
fn main() {
Foo::f("hi");
println!("done");
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0261]: use of undeclared lifetime name `'a`
--> main.rs:4:14
|
4 | fn f(x: &'a str) {}
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
4 | fn f<'a>(x: &'a str) {}
| ++++
help: consider introducing lifetime `'a` here
|
3 | impl<'a> Foo {
| ++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0261`.
Here the method-level declaration is the natural one — the lifetime belongs to this method's signature, not to the type — and with fn f<'a> the method compiles and prints through its caller as expected. Introduce a lifetime at the level that owns the relationship it describes: on the method when only the method mentions it, on the impl when the impl header or several methods share it.
Trait definitions: one error per item that uses the name
A trait definition is an item of its own, and so is each impl of it. Using 'a in both, declaring it in neither, produces one error in the trait and one in the impl:
trait T {
fn f(x: &'a str);
}
struct S;
impl T for S {
fn f(x: &'a str) {}
}
fn main() {
S::f("hi");
println!("done");
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0261]: use of undeclared lifetime name `'a`
--> main.rs:2:14
|
2 | fn f(x: &'a str);
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
2 | fn f<'a>(x: &'a str);
| ++++
help: consider introducing lifetime `'a` here
|
1 | trait T<'a> {
| ++++
error[E0261]: use of undeclared lifetime name `'a`
--> main.rs:8:14
|
8 | fn f(x: &'a str) {}
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
8 | fn f<'a>(x: &'a str) {}
| ++++
help: consider introducing lifetime `'a` here
|
7 | impl<'a> T for S {
| ++++
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0261`.
Each error again offers two introduction points, one on the method and one on the enclosing trait or impl. Declaring the lifetime on the method in both places — the trait declaration and its implementation must match — repairs the program:
trait T {
fn f<'a>(x: &'a str) -> usize;
}
struct S;
impl T for S {
fn f<'a>(x: &'a str) -> usize {
x.len()
}
}
fn main() {
println!("{}", S::f("hi"));
}
$ rustc --edition 2021 main.rs -o main.bin
$ ./main.bin
2
The program prints 2 and exits with status 0. Putting the lifetime on the trait instead, trait T<'a>, is a different design, not the same fix spelled differently: it makes the lifetime part of the trait itself, so each type implements the trait for one lifetime, and implementers and callers both have to name it. Reach for the method-level declaration unless the lifetime really is a property of the trait.
Two undeclared names: one error per use, not per signature
A signature using two undeclared lifetimes gets two errors, one for each name, each with its own help inserting only that name:
fn f(x: &'a str, y: &'b str) {}
fn main() {
f("hi", "yo");
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0261]: use of undeclared lifetime name `'a`
--> main.rs:1:10
|
1 | fn f(x: &'a str, y: &'b str) {}
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
1 | fn f<'a>(x: &'a str, y: &'b str) {}
| ++++
error[E0261]: use of undeclared lifetime name `'b`
--> main.rs:1:22
|
1 | fn f(x: &'a str, y: &'b str) {}
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'b` here
|
1 | fn f<'b>(x: &'a str, y: &'b str) {}
| ++++
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0261`.
Read the two helps together, not one at a time: applying only the first leaves the second error standing. The finished declaration lists both names:
fn f<'a, 'b>(x: &'a str, y: &'b str) -> usize {
x.len() + y.len()
}
fn main() {
println!("{}", f("hi", "yo"));
}
$ rustc --edition 2021 main.rs -o main.bin
$ ./main.bin
4
The program prints 4 and exits with status 0. The per-use rule also applies to a single name used twice. A function returning the same undeclared lifetime it takes as a parameter is charged twice:
fn f(x: &'a str, y: &'a str) {}
fn main() {
f("hi", "yo");
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0261]: use of undeclared lifetime name `'a`
--> main.rs:1:10
|
1 | fn f(x: &'a str, y: &'a str) {}
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
1 | fn f<'a>(x: &'a str, y: &'a str) {}
| ++++
error[E0261]: use of undeclared lifetime name `'a`
--> main.rs:1:22
|
1 | fn f(x: &'a str, y: &'a str) {}
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
1 | fn f<'a>(x: &'a str, y: &'a str) {}
| ++++
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0261`.
Two errors here do not mean two missing declarations. The count in the aborting line counts use sites; one <'a> on the function clears both. The same counting shows up when only the return type names the undeclared lifetime — one use, one error, with the span on the return type:
fn f(x: &str) -> &'a str {
x
}
fn main() {
println!("{}", f("hi"));
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0261]: use of undeclared lifetime name `'a`
--> main.rs:1:19
|
1 | fn f(x: &str) -> &'a str {
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
1 | fn f<'a>(x: &str) -> &'a str {
| ++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0261`.
That last shape is also the one where the second repair is usually the right one. The parameter is already elided; declaring 'a ties the return to a lifetime nothing else in the signature mentions. Removing the name from the return type instead lets elision tie the return to the single input, which is what the body does:
fn f(x: &str) -> &str {
x
}
fn main() {
println!("{}", f("hi"));
}
$ rustc --edition 2021 main.rs -o main.bin
$ ./main.bin
hi
The program prints hi and exits with status 0. Before declaring any lifetime on a function, check whether the name is doing work. If every use of it can be an elided & instead, delete the name and the error — and the declaration — both go away. Declaration is for relationships elision cannot express: a return tied to one of several inputs, or to self in a particular way, and for items, like structs, where elision does not apply at all.
Bounds: a lifetime in a bound needs declaring too
The name does not have to sit on a reference to trigger this error. A lifetime used only in a bound is still a use:
fn f<T: 'a>(x: T) {}
fn main() {
f(42);
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0261]: use of undeclared lifetime name `'a`
--> main.rs:1:9
|
1 | fn f<T: 'a>(x: T) {}
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
1 | fn f<'a, T: 'a>(x: T) {}
| +++
warning: unused variable: `x`
--> main.rs:1:13
|
1 | fn f<T: 'a>(x: T) {}
| ^ help: if this is intentional, prefix it with an underscore: `_x`
|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0261`.
The help here inserts 'a ahead of the type parameter, fn f<'a, T: 'a> — lifetimes are listed before type parameters in the declaration. The same holds in a where clause and on a type alias: an alias that declares 'b but uses 'a in its definition fails with E0261 on the 'a, and its help offers to add 'a alongside the 'b it already has. A declaration somewhere in the brackets is not enough; the specific name used has to be among the names declared. Declaring a different lifetime, however similar the signature looks, leaves this error exactly where it was.
The names that never need declaring: 'static and '_
Two lifetime spellings are provided by the language and can be used with no declaration anywhere. 'static is the lifetime of the whole program, and '_ is a placeholder asking the compiler to infer the lifetime in that position:
fn f(x: &'static str, y: &'_ str) -> usize {
x.len() + y.len()
}
fn main() {
println!("{}", f("hi", "yo"));
}
$ rustc --edition 2021 main.rs -o main.bin
$ ./main.bin
4
The program prints 4 and exits with status 0, with no angle brackets on the function at all. A struct field typed &'static str likewise compiles with no parameter on the struct — string literals have exactly that type, which is why the pattern is common for stored messages and names. The placeholder has limits the named form does not: '_ works where elision can infer a lifetime, which is function signatures, and not where a stored type needs a named parameter. A struct field typed &'_ str does not produce E0261 — it produces E0106, in the next section — because the fault there is not an undeclared name but a missing one.
Neighboring error: no lifetime written at all is E0106
E0261 requires a name that was written but not declared. A struct field that is a bare reference, with no lifetime written in any form, is a different fault:
struct Foo {
x: &str,
}
fn main() {
let f = Foo { x: "hi" };
println!("{}", f.x);
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0106]: missing lifetime specifier
--> main.rs:2:8
|
2 | x: &str,
| ^ expected named lifetime parameter
|
help: consider introducing a named lifetime parameter
|
1 ~ struct Foo<'a> {
2 ~ x: &'a str,
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0106`.
The code is E0106, missing lifetime specifier, the header says a lifetime is missing rather than undeclared, and the help rewrites two lines at once — it adds the parameter to the struct and writes the name into the field. The &'_ str field lands here too:
struct Foo {
x: &'_ str,
}
fn main() {
println!("done");
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0106]: missing lifetime specifier
--> main.rs:2:9
|
2 | x: &'_ str,
| ^^ expected named lifetime parameter
|
help: consider introducing a named lifetime parameter
|
1 ~ struct Foo<'a> {
2 ~ x: &'a str,
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0106`.
The split to remember is by what is on the page. A name is written and matches no declaration: E0261. No usable name is written where the type needs one: E0106. The repairs converge — both end with a declared, named parameter — but searching by the wrong code will not find the other error's documentation.
Neighboring errors: declared lifetimes that do not fit are E0621 and E0623
Once every name is declared, lifetime faults move to later codes, and neither of them is fixed by adding a declaration. In this function 'a is properly declared, but the body can return the second parameter, whose type carries no 'a:
fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 {
if x > y { x } else { y }
}
fn main() {
println!("{}", foo(&2, &1));
}
$ rustc --edition 2021 main.rs -o main.bin
error[E0621]: explicit lifetime required in the type of `y`
--> main.rs:2:27
|
2 | if x > y { x } else { y }
| ^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `y`
|
1 | fn foo<'a>(x: &'a i32, y: &'a i32) -> &'a i32 {
| ++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0621`.
That is E0621, explicit lifetime required: the name exists, and the fault is that a type in the signature does not carry it where the body needs it to. The repair edits the type of y, not the declaration list. One step further along, two declared lifetimes that the body treats as interchangeable produce a mismatch. The official example for E0623 builds a conversion trait over two lifetimes and a function returning one lifetime's data through the other; compiling it gives E0623, lifetime mismatch, on the parameter whose declared lifetimes differ from the return type, alongside a plain region error on the return expression. Nothing in that output suggests introducing a lifetime, because every name in it is already introduced — the fix is a bound relating the two lifetimes, or using one lifetime where two were declared. E0261 is the only one of the three whose entire content is a missing declaration.
The exact rule: a lifetime must be declared on the item that uses it
The official page for E0261 states the fault in one sentence: an undeclared lifetime was used. Its erroneous examples are the three shapes this guide opened with — a function fn foo(x: &'a str), a struct with a field x: &'a str, and an impl block written impl Foo<'a> for a struct that declares 'a — and its fixes are the declarations: lifetime parameters on the function and the struct, and, for the impl, declaring the block as impl<'a> Foo<'a>, with the method inside it then using 'a with no parameter of its own. It adds the point the impl section above is built on: impl blocks declare lifetime parameters separately — implementing a type that has a lifetime parameter means adding the parameter to the impl block as well. The page carries no note retiring or replacing this code; E0261 is the current code for this fault.
The Reference's page on lifetime elision covers the other repair and the two names that need no declaration. Lifetimes can be elided in function, function pointer, and closure trait signatures where the compiler can infer a sensible default: each elided lifetime in the parameters becomes a distinct lifetime parameter, and if there is exactly one lifetime among the parameters, it is assigned to all elided output lifetimes, with a further rule assigning the receiver's lifetime in method signatures. The same page states that the placeholder lifetime '_ can be used to have a lifetime inferred in the same way, and that it is an error to elide lifetime parameters that cannot be inferred — which is where the removal repair stops working and a declaration, or E0106, takes over.
The fixes, ranked
- First, declare the lifetime on the item that uses it:
<'a>on the function, struct, enum, or trait method whose signature names it. This is the repair the compiler offers, and for structs and enums it is the only one — elision does not apply to stored types. - Second, for an impl block, declare the lifetime on the impl —
impl<'a> Foo<'a>— whenever the impl header names it or the block's methods share it. That one declaration covers the header and every method; a method-level declaration alone leaves an undeclared use in the header standing. - Third, remove the name and let elision supply the lifetime, when the item is a function and the relationship the name expressed is the one elision would infer anyway — one input, or a method receiver. This deletes the error instead of satisfying it, and leaves the shortest signature.
- Fourth, write
'_where you want the position of a lifetime visible but its name irrelevant, in function signatures, or'staticwhere the data genuinely lives for the whole program. Neither ever needs a declaration, and neither can substitute for a named parameter on a stored type.
Which fix for which cause
- Function parameter, return type, or bound uses a lifetime the function does not declare: E0261, span on the use, help offering the name in the function's brackets. Declare it there, or remove the name if elision covers the position.
- Struct or enum field uses an undeclared lifetime: E0261, help offering the parameter on the type. Declare it on the struct or enum; there is no elision alternative.
- Impl header uses the type's lifetime: E0261 on the header line. Declare it on the impl,
impl<'a> Foo<'a>; declaring it on a method does not clear the header. - Method uses a lifetime declared on neither the method nor its impl: E0261, with helps for both levels. Declare it on the method if only the method uses it, on the impl if the block shares it.
- Trait method uses an undeclared lifetime: E0261 in the trait and again in each impl that repeats the signature. Declare it in both places, or put it on the trait itself as a design change.
- Two undeclared names, or one name used twice: E0261 once per use site. One declaration per distinct name clears every use of that name.
- A bound or a
whereclause uses an undeclared lifetime: E0261, span in the bound. Declare the lifetime ahead of the type parameters in the same brackets. - The signature writes
'staticor, in a function signature,'_: no error and no declaration needed. A&'_field in a struct is E0106 instead. - A struct field writes no lifetime at all: E0106, not E0261. Add the named parameter to the type and write it into the field.
- Every name is declared but a parameter type does not carry the lifetime the body returns: E0621. Add the lifetime to that parameter's type; the declaration list is already complete.
- Every name is declared but two lifetimes do not match where the body connects them: E0623. Add a bound relating them, or collapse them to one lifetime.
Checklist
- Find the item whose brackets are missing the name. The span marks the use; the declaration belongs on the item that contains that use — function, struct, enum, trait, or impl — and a declaration on a neighboring item, even the struct behind an impl, does not count.
- Count errors by use sites, not by missing names. One undeclared name used three times is three errors and one declaration; two undeclared names are two declarations, and both helps have to be applied together.
- In an impl block, check the header before the methods. If the header names the lifetime, the impl-level declaration is mandatory, whatever the methods declare.
- Read dual helps as alternatives with different reach, not as a pair to apply blindly. The method-level and impl-level suggestions both silence the method's error; only the impl-level one silences the header's.
- Before declaring, ask whether the name earns its place. A function whose named lifetime is exactly what elision would infer is shorter and clearer with the name removed; a struct has no such choice.
- Check the code before searching for help. A written name with no declaration is E0261; a missing name is E0106; a declared name in the wrong place or mismatched is E0621 or E0623, and adding declarations fixes only the first.
Related guides on this site
- Name Already Used for Generic E0403 Fix
- E0415 Duplicate Parameter Name Fix
- E0659 Ambiguous Name Fix
- E0426 Undeclared Label Used Fix
Sources
- Rust Compiler Error Index, E0261 — for an undeclared lifetime being used, for the erroneous examples of a function, a struct field, and an impl block using
'awithout declaring it, for fixing them by declaring lifetime parameters, and for impl blocks declaring lifetime parameters separately from the type they implement. - The Rust Reference, Lifetime elision — for lifetimes being elided in function signatures where a sensible default can be inferred, for each elided parameter lifetime becoming a distinct parameter and a single input lifetime being assigned to all elided outputs, for the receiver rule in method signatures, for the placeholder lifetime
'_having a lifetime inferred in the same way, and for eliding a lifetime that cannot be inferred being an error. - Rust Compiler Error Index, E0106 — for a lifetime missing from a type, for the struct, enum, and type alias examples with no lifetime written, and for the elision conditions a function signature must meet.
- Rust Compiler Error Index, E0621 — for a mismatch between the lifetimes in a function signature and the data-flow in its body, and for fixing it by adding the explicit lifetime to the parameter type the body returns.
- Rust Compiler Error Index, E0623 — for a lifetime not matching what was expected, and for fixing the mismatch by bounding one lifetime by the other or by using only one lifetime.
Keep Exploring
The full Rust hub \u2014 ownership, structs and enums, async, and measured comparisons.
Every guide on the site in one list, grouped by topic.
Every browser-only checker and verifier on the site.
The C++, Python, Sysadmin, Rust, Go, and TypeScript hubs.