Rust

Struct Literal on Non-Struct Type E0071 Fix

Braces with fields are how Rust builds a struct, a struct-like enum variant, or a union - and nothing else. Point that syntax at a type alias for a primitive, a tuple, an array, or a reference and the compiler stops with E0071: the name in front of the braces does not name anything that has fields to fill in. An alias does not change the answer - an alias to a real struct works with braces, while an alias to anything else fails - and two nearby shapes surprise: tuple structs accept numbered fields in braces, and an enum's own name draws a different code, E0574. The fix matches the intent: assign the plain value, define a real struct, or call the tuple form with parentheses. This guide shows each failing shape, the neighboring mistakes that draw different errors, the shapes that compile and run, and the repairs running.

Written December 2, 2026 · Tested with Rust 1.99.0 · 16 min read

By the end of this guide
  • The rule underneath: braces need a type that has fields
  • How to read the diagnostic
  • The first failure: the index example
  • Every alias to a non-struct draws the same code

Written December 2, 2026

Tested with Rust 1.99.0

What this guide is

Error E0071 means struct literal syntax was used to create an item that is not a structure or enum variant. The error codes index puts it in one sentence: "A structure-literal syntax was used to create an item that is not a structure or enum variant."

A struct literal is a path followed by braces holding field values, as in Point { x: 1, y: 2 }. That form only works when the path names a struct, a struct-like enum variant, or a union. This guide shows what happens when the same form is aimed at a type alias for a primitive, a tuple, an array, a bool, or a reference, which shapes sitting next to it draw different codes instead, and which brace forms that look wrong actually compile and run.

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: braces need a type that has fields

A struct literal is a field-by-field construction: each name inside the braces has to correspond to a declared field of the type in front of the braces. A primitive such as u32 has no fields, a tuple has positions rather than named fields, an array has elements rather than fields, and a reference has neither. There is nothing for value: 4 to assign to, so the compiler rejects the whole expression before any field is considered.

A type alias changes nothing by itself, because an alias is only another name for the same type. That cuts both ways, and both ways appear below: an alias to u32 fails with E0071 (writing u32 { value: 4 } directly, with no alias, is a different shape and draws E0574 instead), while an alias to a real struct succeeds with braces - and an alias to String or Vec<i32>, which are real structs underneath, gets past E0071 and fails later, on the unknown field, with E0560.

How to read the diagnostic

The header names what was found: "expected struct, variant or union type, found u32" - the found type changes with the alias target, showing (i32, i32) for a tuple, [u8; 3] for an array, bool, or &i32 for a reference. The span covers only the name in front of the braces, labeled "not a struct". There is no help line in this diagnostic; the repair has to come from deciding what the value was meant to be - a plain value of the aliased type, or a field of a real struct that needs defining.

One reading trap matters: when an alias points at a real struct, the same brace syntax draws E0560 instead. The absence of E0071 there does not mean the alias behaved differently as an alias; it means the alias resolved to a struct, so the literal was legal in form and only the field name was wrong.

The first failure: the index example

The index's erroneous example, verbatim:

Rust
#![allow(unused)]

fn main() {

type U32 = u32;

let t = U32 { value: 4 }; // error: expected struct, variant or union type,
                          // found builtin type `u32`

}
Output
error[E0071]: expected struct, variant or union type, found `u32`
 --> fail_index.rs:7:9
  |
7 | let t = U32 { value: 4 }; // error: expected struct, variant or union type,
  |         ^^^ not a struct

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0071`.

The example is a single alias to a builtin type used with braces, and it draws exactly one E0071 - no second code hides in it. The index gives two corrected forms: assign the plain value (let t: U32 = 4;), or define a real struct named U32 with a value field. Both repairs are shown running below.

Every alias to a non-struct draws the same code

The alias target is the whole story. A tuple alias fails, even though the numbered entries inside the braces match the tuple's positions:

Rust
type PairAlias = (i32, i32);

fn main() {
    let p = PairAlias { 0: 1, 1: 2 };
    println!("{:?}", p);
}
Output
error[E0071]: expected struct, variant or union type, found `(i32, i32)`
 --> fail_alias_tuple.rs:4:13
  |
4 |     let p = PairAlias { 0: 1, 1: 2 };
  |             ^^^^^^^^^ not a struct

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0071`.

An array alias fails the same way, with the array type named in the header:

Rust
type Bytes = [u8; 3];

fn main() {
    let b = Bytes { 0: 1, 1: 2, 2: 3 };
    println!("{:?}", b);
}
Output
error[E0071]: expected struct, variant or union type, found `[u8; 3]`
 --> fail_alias_array.rs:4:13
  |
4 |     let b = Bytes { 0: 1, 1: 2, 2: 3 };
  |             ^^^^^ not a struct

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0071`.

A bool alias is a primitive alias like the index's u32 alias, and the wording is identical apart from the found type:

Rust
type Flag = bool;

fn main() {
    let f = Flag { value: true };
    println!("{}", f);
}
Output
error[E0071]: expected struct, variant or union type, found `bool`
 --> fail_primitive_alias_bool.rs:4:13
  |
4 |     let f = Flag { value: true };
  |             ^^^^ not a struct

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0071`.

A reference alias fails too - a reference is a pointer with a borrow attached, not a container with fields:

Rust
type NumRef<'a> = &'a i32;

fn main() {
    let x = 5;
    let r = NumRef { value: &x };
    println!("{}", r);
}
Output
error[E0071]: expected struct, variant or union type, found `&i32`
 --> fail_alias_slice_ref.rs:5:13
  |
5 |     let r = NumRef { value: &x };
  |             ^^^^^^ not a struct

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0071`.

Tuple, array, bool, reference: when an alias in front of the braces resolves to one of these non-struct types, E0071 is the code, and the found type in the header tells you what it did resolve to.

The shapes that are not this error: aliases to real structs

An alias to String does not draw E0071. String is a struct, so the literal is well-formed in shape, and the compiler moves on to checking the fields - where value fails, because String has no field with that name:

Rust
type Name = String;

fn main() {
    let s = Name { value: 4 };
    println!("{}", s);
}
Output
error[E0560]: struct `String` has no field named `value`
 --> fail_alias_string.rs:4:20
  |
4 |     let s = Name { value: 4 };
  |                    ^^^^^ `String` does not have this field
  |
  = note: all struct fields are already assigned

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0560`.

An alias to Vec<i32> lands in the same place, for the same reason:

Rust
type Wrapper = Vec<i32>;

fn main() {
    let w = Wrapper { value: 4 };
    println!("{:?}", w);
}
Output
error[E0560]: struct `Vec<i32>` has no field named `value`
 --> fail_generic_alias.rs:4:23
  |
4 |     let w = Wrapper { value: 4 };
  |                       ^^^^^ `Vec<i32>` does not have this field
  |
  = note: all struct fields are already assigned

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0560`.

The fix here is not to drop the braces for a plain assignment of the alias type; it is to build the struct the way that struct is actually built - for String and Vec, through their constructors and associated functions, one of which is shown in the repairs.

The shape that is not this error: an enum's own name

An enum is built through one of its variants, never through the enum's own name. Aiming braces at the enum name itself draws E0574, whose header repeats E0071's opening words - "expected struct, variant or union type" - but names the found kind as an enum and carries a different code:

Rust
enum Color {
    Red,
    Blue,
}

fn main() {
    let c = Color { value: 4 };
    match c {
        Color::Red => println!("red"),
        Color::Blue => println!("blue"),
    }
}
Output
error[E0574]: expected struct, variant or union type, found enum `Color`
 --> fail_enum_name_braces.rs:7:13
  |
7 |     let c = Color { value: 4 };
  |             ^^^^^ not a struct, variant or union type

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0574`.

If the header says "found enum", the code is E0574 and the repair is to name a variant, as in the repairs below. In the alias shapes shown in this guide, a header naming a concrete non-struct type carries E0071; the code in the error line, not the found type alone, is the reliable distinguisher - a builtin type written directly, as in u32 { value: 4 }, also draws E0574.

Neighboring codes: E0063 and E0560 on real structs

Two mistakes on real structs sit next to E0071 and keep their own codes.

A real struct literal that leaves out a field - E0063. The brace form is right and the type is right; the initializer is incomplete:

Rust
struct Point {
    x: i32,
    y: i32,
}

fn main() {
    let p = Point { x: 1 };
    println!("{} {}", p.x, p.y);
}
Output
error[E0063]: missing field `y` in initializer of `Point`
 --> neighbour_missing_field_e0063.rs:7:13
  |
7 |     let p = Point { x: 1 };
  |             ^^^^^ missing `y`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0063`.

A tuple struct literal with named fields - E0560. A tuple struct's fields are numbered, not named, so writing names draws one E0560 per name, and the help shows the parenthesized call form that a tuple struct actually takes:

Rust
struct Pair(i32, i32);

fn main() {
    let p = Pair { x: 1, y: 2 };
    println!("{} {}", p.0, p.1);
}
Output
error[E0560]: struct `Pair` has no field named `x`
 --> neighbour_tuple_struct_missing.rs:4:20
  |
1 | struct Pair(i32, i32);
  |        ---- `Pair` defined here
...
4 |     let p = Pair { x: 1, y: 2 };
  |                    ^ field does not exist
  |
help: `Pair` is a tuple struct, use the appropriate syntax
  |
4 -     let p = Pair { x: 1, y: 2 };
4 +     let p = Pair(/* i32 */, /* i32 */);
  |

error[E0560]: struct `Pair` has no field named `y`
 --> neighbour_tuple_struct_missing.rs:4:26
  |
1 | struct Pair(i32, i32);
  |        ---- `Pair` defined here
...
4 |     let p = Pair { x: 1, y: 2 };
  |                          ^ field does not exist
  |
help: `Pair` is a tuple struct, use the appropriate syntax
  |
4 -     let p = Pair { x: 1, y: 2 };
4 +     let p = Pair(/* i32 */, /* i32 */);
  |

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0560`.

E0063 and E0560 both mean the literal form was accepted and its contents were wrong. E0071 means the form itself was used on a type that has no fields at all.

What does work: tuple forms with numbered fields in braces

A tuple struct can be written with braces if the fields inside are numbered. This program compiles and runs, printing both values:

Rust
struct Pair(i32, i32);

fn main() {
    let p = Pair { 0: 1, 1: 2 };
    println!("{} {}", p.0, p.1);
}
Output
1 2

A tuple enum variant accepts the same numbered-field brace form:

Rust
enum Shape {
    Point(i32, i32),
}

fn main() {
    let s = Shape::Point { 0: 1, 1: 2 };
    match s {
        Shape::Point(x, y) => println!("{} {}", x, y),
    }
}
Output
1 2

These are worth knowing about before "fixing" them: the brace form is not reserved for named fields. What a tuple form cannot take in braces is field names, as the E0560 case above shows. The parenthesized forms in the repairs remain the usual style for tuple structs and variants.

What does work: unit structs, aliases to structs, named structs, and unions

A unit struct - a struct with no fields - takes empty braces:

Rust
struct Marker;

fn main() {
    let m = Marker {};
    println!("{:?}", std::mem::size_of_val(&m));
}
Output
0

An alias to a real struct takes braces with that struct's fields, because the alias resolves to the struct:

Rust
struct Point {
    x: i32,
    y: i32,
}

type PointAlias = Point;

fn main() {
    let p = PointAlias { x: 1, y: 2 };
    println!("{} {}", p.x, p.y);
}
Output
1 2

A plain named struct literal is the ordinary case the syntax exists for:

Rust
struct Point {
    x: i32,
    y: i32,
}

fn main() {
    let p = Point { x: 3, y: 4 };
    println!("{} {}", p.x, p.y);
}
Output
3 4

And a union takes braces with exactly one field - unions are the third kind named in E0071's header:

Rust
union Value {
    i: i32,
    f: f32,
}

fn main() {
    let v = Value { i: 42 };
    println!("{}", unsafe { v.i });
}
Output
42

Struct, struct-like variant, union, plus the tuple forms with numbered fields: that is the full set the brace syntax serves.

Struct literal mistakes cluster together. For a field named twice in one literal, see Field Specified More Than Once E0062 Fix. For assigning to something that is not a place expression, see Assign to Non-Place Expression E0070 Fix. For a tuple pattern with the wrong number of fields, see Tuple Pattern Field Count E0023 Fix.

The repairs

Assign the plain value. This is the index's first corrected form: an alias to u32 is a u32, so it takes a plain value, with no braces and no field name:

Rust
type U32 = u32;

fn main() {
    let t: U32 = 4;
    println!("{}", t);
}
Output
4

Define a real struct. This is the index's second corrected form: if the value really has a value field, the name has to be a struct that declares it:

Rust
struct U32 {
    value: u32,
}

fn main() {
    let t = U32 { value: 4 };
    println!("{}", t.value);
}
Output
4

Call a tuple struct with parentheses. The parenthesized form is the standard construction for a tuple struct, matching the help in the E0560 transcript above:

Rust
struct Pair(i32, i32);

fn main() {
    let p = Pair(1, 2);
    println!("{} {}", p.0, p.1);
}
Output
1 2

Call a tuple variant with parentheses, through its enum path:

Rust
enum Shape {
    Point(i32, i32),
}

fn main() {
    let s = Shape::Point(1, 2);
    match s {
        Shape::Point(x, y) => println!("{} {}", x, y),
    }
}
Output
1 2

Use braces on a struct-like variant. Braces belong on the variant, not on the enum name - this is the repair for the E0574 shape:

Rust
enum Shape {
    Rect { width: i32, height: i32 },
}

fn main() {
    let s = Shape::Rect { width: 3, height: 4 };
    match s {
        Shape::Rect { width, height } => println!("{} {}", width, height),
    }
}
Output
3 4

Name a unit variant by its path. A unit variant has no fields and takes no braces at all:

Rust
enum Color {
    Red,
    Blue,
}

fn main() {
    let c = Color::Red;
    match c {
        Color::Red => println!("red"),
        Color::Blue => println!("blue"),
    }
}
Output
red

Build an aliased struct through its own API. An alias to Vec<i32> is built the way a Vec is built - here with from - not with a field literal:

Rust
type Wrapper = Vec<i32>;

fn main() {
    let w = Wrapper::from(vec![1, 2, 3]);
    println!("{:?}", w);
}
Config
[1, 2, 3]

Fixes in reach order

First, read the code and the found type in the header together. In the alias shapes in this guide, a found primitive, tuple, array, or reference carries E0071; an enum name - and a builtin type written directly, with no alias - draws E0574 instead.

Second, decide what the value was meant to be. If it was a plain value of the aliased type, drop the braces and the field name and assign the value directly.

Third, if the value was meant to carry named fields, define a real struct with those fields - or check whether the name was misspelled and a struct with that name already exists elsewhere.

Fourth, if the target is a tuple struct or tuple variant, use parentheses - or keep braces with numbered fields, which also compiles.

Last, leave the legal brace forms alone: named structs, struct-like variants, unions, unit structs with empty braces, and aliases that resolve to real structs. Do not rewrite them while fixing the E0071 next to them.

Decision summary

E0071 fired for every struct literal aimed at a non-struct through an alias: the index example (an alias to u32), an alias to a tuple, an alias to an array, an alias to bool, and an alias to a reference - in each case exactly one E0071, with the header naming the resolved type and the span labeled "not a struct". It did not fire for an alias to String or an alias to Vec<i32>, which resolved to real structs and drew E0560 for the unknown field, nor for an enum's own name in braces, which drew E0574, nor for a real struct literal missing a field, which drew E0063, nor for a tuple struct literal with named fields, which drew two E0560 errors. The shapes that compiled and ran were a tuple struct and a tuple variant with numbered fields in braces, a unit struct with empty braces, an alias to a real struct with braces, a plain named struct literal, and a union literal with one field. The repairs that ran were assigning the aliased value directly, defining a real struct with the field, calling a tuple struct and a tuple variant with parentheses, using braces on a struct-like variant, naming a unit variant by its path, and building an aliased Vec with an associated function.

Checklist

  • Braces with fields require a struct, a struct-like enum variant, or a union in front of them - nothing else.
  • A type alias is transparent: an alias to a non-struct draws E0071, and an alias to a real struct behaves exactly like the struct, including drawing E0560 for an unknown field.
  • An enum is never built through its own name; that shape is E0574, and the repair is to name a variant.
  • A real struct with a missing field is E0063, and a tuple struct with named fields is E0560 - both mean the form was accepted and the contents were wrong.
  • Tuple structs and tuple variants accept numbered fields in braces, though parentheses are the usual form.
  • The index's two repairs cover most cases: assign the plain value, or define the real struct.

Sources

  • Rust error codes index, E0071 - a structure-literal syntax was used to create an item that is not a structure or enum variant; the erroneous example aliases U32 to u32 and writes U32 { value: 4 }, and the corrected forms assign let t: U32 = 4; or define a real struct U32 { value: u32 }.
  • Rust error codes index, E0560 - an unknown field was specified into a structure; the code drawn when an alias resolves to a real struct, and when a tuple struct literal uses named fields.
  • Rust error codes index, E0574 - something other than a struct, variant or union was used when one was expected; the code drawn when braces are aimed at an enum's own name.
  • Rust error codes index, E0063 - a struct's or struct-like enum variant's field was not provided; the code drawn by a real struct literal that leaves out a field.

Keep Exploring