E0069 Return Without Value Fix
Written December 2, 2026 · Tested with Rust 1.99.1 · 16 min read
- The rule underneath: a bare return returns unit
- How to read the diagnostic
- The first failure: the index example
- The same error with other return types and in other places
Written December 2, 2026
Tested with Rust 1.99.1
What this guide is
Error E0069 means a function used return; - a return with no value - while its declared return type is not (). The error codes index puts it plainly: since return; is just like return ();, there is a mismatch between the function's return type and the value being returned, whenever that return type is anything other than unit.
In the shapes probed in this guide, E0069 fires on its own for the index example returning u8, for functions returning String and bool, for a bare return inside a branch and inside a loop, for a method, for a closure with an annotated return type, through a type alias, with a generic return type, and in a function whose return type is !. A second code rides along when the same program also uses an unresolved name, which drew E0425 alongside. Neighboring shapes draw a different code instead: returning () explicitly, returning a value of the wrong type, and falling off the end of a typed function with no tail value all drew E0308. At the boundary, a bare return in a function returning () - written explicitly or left implicit - and a bare return in main compile and run. This guide shows the E0069 shapes, the ride-along and neighboring shapes, the boundary, and the repairs.
Build every program in this guide with rustc --edition 2021. In the compiler transcripts, the file names are the bare names shown on the command line.
The rule underneath: a bare return returns unit
A return; is not an incomplete return waiting for a value to be inferred. It is a complete return whose value is (). That is why the check is so simple: if the function's declared return type is (), a bare return matches and compiles; if it is anything else - a number, a string, a generic parameter, even ! - the bare return mismatches, and the compiler refuses it with E0069 before any code runs.
So the question at every bare return is what the function owes its caller. If it owes a value, the return has to carry one of the right type, or the function has to reach a tail expression of that type instead. If it owes nothing, the honest repair is the other direction: change the declared return type to () and fix the callers that expected a value. There is no annotation that makes a bare return supply a default.
How to read the diagnostic
The E0069 header names the shape directly: "return; in a function whose return type is not ()", in the probed shapes. One span underlines the return type in the signature and names what was expected - "expected u8 because of this return type" for the index shape, "expected String", "expected bool", and "expected T" in the other probed shapes - and a second span underlines the return itself with "return type is not ()". A help block then proposes the smallest repair it can: "give the return a value of the expected type", written out as return 42; for a u8 return, return false; for a bool return, and return Default::default(); for a String return, in the probed shapes. For a generic return type the help proposes a placeholder instead - return /* value */; - because the compiler does not know a value of that type to suggest, and for a return type of ! no help block appeared at all in the probed shape.
The count does not simply follow the bare returns, in the probed shapes. A function with two bare returns - one in a branch, one after it - drew exactly one E0069, on the first bare return, while two functions with one bare return each drew exactly two, one per function. Fix the reported return first and recompile: a second bare return in the same function can be waiting behind the first report.
The first failure: the index example
The index's erroneous example, verbatim:
#![allow(unused)]
fn main() {
// error
fn foo() -> u8 {
return;
}
}
error[E0069]: `return;` in a function whose return type is not `()`
--> fail_index.rs:5:5
|
4 | fn foo() -> u8 {
| -- expected `u8` because of this return type
5 | return;
| ^^^^^^ return type is not `()`
|
help: give the `return` a value of the expected type
|
5 | return 42;
| ++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0069`.
Exactly one E0069, and no other error code. Nothing else in the program is wrong: the function is never even called. The declaration promises a u8 to any caller, and the bare return tries to hand back () instead - the mismatch is inside the function alone, and it is reported whether or not the function is used.
The same error with other return types and in other places
The owed type does not have to be a number. A function returning String whose body is a bare return drew exactly one E0069 in the probed shape, and the help reached for a default value of the expected type:
error[E0069]: `return;` in a function whose return type is not `()`
--> fail_string.rs:2:5
|
1 | fn greet() -> String {
| ------ expected `String` because of this return type
2 | return;
| ^^^^^^ return type is not `()`
|
help: give the `return` a value of the expected type
|
2 | return Default::default();
| ++++++++++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0069`.
Position inside the function does not matter. A bare return inside an if branch in a function returning bool drew exactly one E0069 in the probed shape - an early return owes the same value a final return does:
error[E0069]: `return;` in a function whose return type is not `()`
--> fail_bool_branch.rs:3:9
|
1 | fn ready(flag: bool) -> bool {
| ---- expected `bool` because of this return type
2 | if flag {
3 | return;
| ^^^^^^ return type is not `()`
|
help: give the `return` a value of the expected type
|
3 | return false;
| +++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0069`.
The same shape inside a loop drew exactly one E0069 in the probed shape, with the same header and help. Neither does the kind of callable matter: a method returning u8 with a bare return drew exactly one E0069 in the probed shape:
error[E0069]: `return;` in a function whose return type is not `()`
--> fail_method.rs:4:9
|
3 | fn value(&self) -> u8 {
| -- expected `u8` because of this return type
4 | return;
| ^^^^^^ return type is not `()`
|
help: give the `return` a value of the expected type
|
4 | return 42;
| ++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0069`.
A closure with an annotated return type - || -> u8 - with a bare return drew exactly one E0069 in the probed shape, with the spans on the closure's annotation and its return. Naming the type differently changes nothing: a function returning a type alias for u8 drew exactly one E0069 in the probed shape, because the alias still is not (). A function with a generic return type drew exactly one E0069 in the probed shape:
error[E0069]: `return;` in a function whose return type is not `()`
--> fail_generic.rs:2:5
|
1 | fn make<T>() -> T {
| - expected `T` because of this return type
2 | return;
| ^^^^^^ return type is not `()`
|
help: give the `return` a value of the expected type
|
2 | return /* value */;
| +++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0069`.
The generic shape is the one place the help cannot hand you a value: it proposes a placeholder, and the real repair is to return a value of the generic type the caller supplies - or to rethink a signature that promises a value of a type the function cannot construct on that path.
Even ! is not unit. A function declared to return ! - the never type - whose body is a bare return drew exactly one E0069 in the probed shape, and no help block:
error[E0069]: `return;` in a function whose return type is not `()`
--> neighbour_never_return.rs:2:5
|
1 | fn foo() -> ! {
| - expected `!` because of this return type
2 | return;
| ^^^^^^ return type is not `()`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0069`.
A never-returning function has to diverge - panic, loop forever, or exit - on every path. A bare return is the opposite of diverging, so it fails here under the same code rather than under a mismatch code.
The shape where a second code rides along
Other errors in the same program are reported alongside E0069. A program whose function had a bare return and whose main also used an unresolved name drew E0425 and E0069 together in the probed shape, ending with "aborting due to 2 previous errors":
error[E0425]: cannot find value `missing_name` in this scope
--> ride_unknown_name.rs:5:30
|
5 | println!("{} {}", foo(), missing_name);
| ^^^^^^^^^^^^ not found in this scope
error[E0069]: `return;` in a function whose return type is not `()`
--> ride_unknown_name.rs:2:5
|
1 | fn foo() -> u8 {
| -- expected `u8` because of this return type
2 | return;
| ^^^^^^ return type is not `()`
|
help: give the `return` a value of the expected type
|
2 | return 42;
| ++
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0069, E0425.
For more information about an error, try `rustc --explain E0069`.
Giving the return its value clears the E0069 in that shape and leaves the E0425 standing - the unresolved name is a separate problem that happens to share the output.
The shapes that are not this error
Writing the unit value out in full is not this error - it is the ordinary mismatch code. Returning () explicitly from a function returning u8 drew exactly one E0308 in the probed shape, "mismatched types", with the span on the () and the expected and found types:
error[E0308]: mismatched types
--> neighbour_return_unit_value.rs:2:12
|
1 | fn foo() -> u8 {
| -- expected `u8` because of return type
2 | return ();
| ^^ expected `u8`, found `()`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0308`.
That pair is worth remembering: return; and return (); mean the same thing, but the compiler reports them under different codes - E0069 for the bare form, E0308 for the written-out form. Searching your output for the code you have, not the meaning you expect, finds the right fix.
A returned value of the wrong type is also E0308. Returning a string literal from a function returning u8 drew exactly one E0308 in the probed shape:
error[E0308]: mismatched types
--> neighbour_return_wrong_type.rs:2:12
|
1 | fn foo() -> u8 {
| -- expected `u8` because of return type
2 | return "hi";
| ^^^^ expected `u8`, found `&str`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0308`.
And owing a value without any return at all is E0308 too. A function returning u8 with an empty body drew exactly one E0308 in the probed shape, with a note that the body implicitly returns () because it has no tail or return expression, and a body whose tail expression is () drew exactly one E0308 in the probed shape the same way. E0069 needs the bare return itself; a missing value with no bare return in sight is reported as a type mismatch.
The boundary: functions that owe nothing
The line is the declared return type, and on the unit side of it the bare return is ordinary code. A function declared -> () with a bare return compiled and ran in the probed shape, printing done, and so did the same function with no return annotation at all - no annotation means (). A bare return in main, after a printed line, compiled and ran in the probed shape: main returns unit, so ending it early with return; is legal, and the line before the return still printed. Returning () in full from a unit function also compiled and ran in the probed shape - on the unit side, the bare and written-out forms are both fine, which is exactly the equivalence that makes the bare form an error on the other side.
Related guides
For a returned value whose type does not match the declared return type - including an explicit return (); in a typed function and a typed function that falls off the end - the neighboring code is E0308. For an unresolved name used in the same program, the neighboring code is E0425.
The repairs
Every repair below starts from the same observation: the function owes a value and the bare return supplies none. Either supply the value, or - only when the value was never really owed - change what the function promises.
Give the return the value it owes. Adding the value the help proposes to the index function compiled and ran in the probed shape, printing 42:
fn foo() -> u8 {
return 42;
}
fn main() {
println!("{}", foo());
}
42
Drop the return and use a tail expression. The same function written with the value as its tail expression, and no return at all, compiled and ran in the probed shape, printing 42 - the idiomatic shape when the value is computed at the end of the function rather than on an early exit.
Give an early return its value. The branch shape from the failing shapes above, with the early return carrying its value and the fall-through path ending in a tail expression, compiled and ran in the probed shape, printing true false:
fn ready(flag: bool) -> bool {
if flag {
return true;
}
false
}
fn main() {
println!("{} {}", ready(true), ready(false));
}
true false
Construct the owed value. The String shape with the return carrying a constructed string compiled and ran in the probed shape, printing hi. A method shape works the same way: the method from the failing shapes, returning the field it owes, compiled and ran in the probed shape, printing 3.
Change the promise when no value is owed. If the function never had a value to give - the bare return was the intent, and the typed signature was the mistake - removing the return annotation makes the function return unit, and the bare return then compiles: that shape compiled and ran in the probed shape, printing done. Every caller that used the result has to be fixed in the same change, because the value they were waiting for no longer exists.
Fixes in reach order
First, read the expected type off the diagnostic. The signature span names it - "expected u8", "expected String", "expected T" in the probed shapes - and that is the type the return has to carry. The help block usually writes the smallest version of the fix for you.
Second, supply a value of that type at the bare return, or restructure the end of the function into a tail expression of that type. That is the whole repair for every probed pure E0069 shape: a literal for a number or a bool, a constructed value for a String, the field or computed result for a method.
Third, recompile before hunting for more bare returns in the same function. In the probed shapes, two bare returns in one function drew only the first one's E0069, while bare returns in two different functions were both reported - the per-function count in the first output understates what a function contains.
Fourth, if no value is genuinely owed, change the signature instead: drop the return annotation, or write -> (), and fix the callers. Do not leave a typed signature in place and silence the error by returning a placeholder value the callers will read as real.
Fifth, if the code in the output is E0308 rather than E0069, the shape is a cousin, not this error: in the probed shapes, an explicit return ();, a returned value of the wrong type, and a typed function with no tail value all drew E0308. Fix those as type mismatches.
Decision summary
E0069 fired on its own in the probed shapes for the index example returning u8 (exactly one E0069), for functions returning String and bool (exactly one E0069 each), for a bare return inside a branch and inside a loop (exactly one E0069 each), for a method and for a closure with an annotated return type (exactly one E0069 each), through a type alias for u8 (exactly one E0069), with a generic return type (exactly one E0069, with a placeholder in the help instead of a value), and in a function returning ! (exactly one E0069, with no help block). Two bare returns in one function drew exactly one E0069, on the first, while one bare return in each of two functions drew exactly two. It rode along with E0425 in a program that also used an unresolved name. It did not fire for a bare return in a function returning () explicitly, in a function with no return annotation, or in main (all compiled and ran), or for returning () in full from a unit function (compiled and ran). The neighboring shapes drew E0308 instead: an explicit return (); in a u8 function, a returned value of the wrong type, an empty typed function body, and a typed function whose tail expression is (). The repairs that compiled and ran were returning the expected value (printing 42), using a tail expression (printing 42), giving an early return its value (printing true false), returning a constructed String (printing hi), returning a field from a method (printing 3), and changing the function to return unit when no value was owed (printing done).
Checklist
- A bare return returns unit, in the probed shapes:
return;isreturn ();, so it matches only a return type of(). - The owed type is named in the diagnostic, in the probed shapes: the signature span says what was expected, and the help proposes a value of that type where it can.
- Every position owes the same value, in the probed shapes: a bare return in a branch, in a loop, in a method, and in a closure drew the same code as one at the end of a plain function.
- Aliases and generics do not soften the rule, in the probed shapes: an alias for
u8and a generic return type both drew E0069, and!drew it too. - The count is per function in the first report, in the probed shapes: two bare returns in one function drew one E0069, and one in each of two functions drew two - recompile after the first fix.
- The bare and written-out forms split across codes, in the probed shapes:
return;in a typed function drew E0069, whilereturn ();in the same function drew E0308. - On the unit side there is no error, in the probed shapes: a bare return in an explicit
-> ()function, in an unannotated function, and inmainall compiled and ran.
Sources
- Rust error codes index, E0069 - the compiler found a function whose body contains a
return;statement but whose return type is not(); sincereturn;is just likereturn ();, there is a mismatch between the function's return type and the value being returned; the erroneous example is a function returningu8whose body is a bare return. - Rust error codes index, E0308 - the expected type did not match the received type; the neighboring code drawn in the probed shapes by an explicit
return ();, by a returned value of the wrong type, and by a typed function with no tail value. - Rust error codes index, E0425 - an unresolved name was used; the neighboring code drawn in the probed shape alongside E0069 by a program that also used an unresolved name.
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.