Skip to Content
E0063: Missing Field in Initializer

error[E0063]: missing field in initializer

You created a struct without giving a value to one of its fields. Every field must be set: Rust has no null and no implicit default values.

Quick fix: Add the missing field, or derive Default and finish the literal with ..Default::default().

Code that triggers E0063

src/main.rs
struct User { name: String, email: String, active: bool, } fn main() { let user = User { name: String::from("Ferris"), email: String::from("[email protected]"), }; println!("{} <{}> {}", user.name, user.email, user.active); }

What the compiler says

error[E0063]: missing field `active` in initializer of `User` --> src/main.rs:8:16 | 8 | let user = User { | ^^^^ missing `active` error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0063`.

Why Rust raises E0063

A struct literal must provide every field. Leaving out active is an error rather than a silent false, because an uninitialised field would be undefined behaviour waiting to happen. The message names the missing field, and lists all of them if several are missing.

How to fix E0063

1. Provide the missing field

Set every field in the struct literal.

src/main.rs
struct User { name: String, email: String, active: bool, } fn main() { let user = User { name: String::from("Ferris"), email: String::from("[email protected]"), active: true, }; println!("{} <{}> {}", user.name, user.email, user.active); }

2. Fill the rest from Default

Derive Default and finish with struct update syntax, ..Default::default(). Any field you don’t set gets its default: an empty String, false for bool, 0 for numbers.

src/main.rs
#[derive(Default)] struct User { name: String, email: String, active: bool, } fn main() { let user = User { name: String::from("Ferris"), ..Default::default() }; println!("{} <{}> {}", user.name, user.email, user.active); }

Learn the concept behind it

The Structs lesson explains the rules behind E0063 with diagrams and more examples. For the official reference, run rustc --explain E0063 or read the E0063 entry in the Rust error index .

Hit a different error? Paste it into the Rust error lookup to find its fix.

Last updated on