E0423 Expected Value Fix
A type name, a module name and a macro name are not values, and E0423 is the compiler saying the name you used lives in the wrong namespace for a value position. This guide separates the shapes that produce it - braced structs called or used bare, an enum or Option used as a value, a module reached with a dot, and a macro missing its exclamation mark - and matches each one to the construction, variant, path or invocation that puts a real value there.
Written November 23, 2026 · Tested with Rust 1.99.1 · 31 min read
- The rule underneath: a type name, a module name or a macro name is not a value
- How to read the diagnostic
- The first failure: a braced struct called with parentheses
- The second failure: a braced struct used as a bare value
Written November 23, 2026
Tested with Rust 1.99.1
What this guide is
Error E0423 is a namespace mismatch in a value position. The error codes index states it in two halves: an identifier was used like a function name, or a value was expected and the identifier exists but belongs to a different namespace. The name is usually spelled correctly and the item is usually in scope - what is wrong is the kind of use. A braced struct name names a type, not a callable constructor. An enum name names a type, not one of its values. A module name names a container, not a value inside it. A macro name names a macro, not a function. In each case the compiler finds the name, finds it in the wrong namespace for the position, and reports E0423 instead of guessing what was meant.
The forms in this guide each reproduce E0423 with a small, complete program, and each uses a name in the wrong namespace in a different way. A braced struct called with parentheses, as if it were a tuple struct. The same kind of struct used as a bare value, with no construction at all. A generic braced struct called with parentheses. A braced struct left bare in return position, where the function promises to return a value of that type. An enum name used as a value, without naming a variant. Option::<i32> used as a value, with a type argument but still no variant. A module reached with a dot, a.I, instead of a path, a::I - the shape the error index itself uses. And a macro called without the exclamation mark, println("hello") instead of println!("hello"). In each family the failing program is small, the full compiler output is shown, and the fix supplies the value the position actually needs: a struct literal with braces and field names, a named variant, a path, or a macro invocation.
Several neighboring results are not E0423 and are worked only in the traps and the decision summary. A tuple struct written with braces and its index as the field name, Wrapper { 0: 5 }, compiles - field syntax accepts the tuple index. A bare tuple-struct name is the constructor function itself, so reading a field off it is E0609, not E0423. Calling a unit struct as if it took an argument is E0618. A bare struct-like enum variant is E0533. A tuple struct written with a named braced field is E0560. And a bare tuple-variant name compiles as the constructor function value, which is why the tuple cases behave differently from the braced cases throughout this guide.
Build every program in this guide with rustc --edition 2021. In the compiler transcripts below, the file names are the bare names shown on the command line.
The rule underneath: a type name, a module name or a macro name is not a value
Rust keeps names in separate namespaces by kind. The Rust Reference lists them: the type namespace holds module declarations, struct, union and enum declarations, enum variant declarations, trait items and type aliases; the value namespace holds function declarations, constant and static items, struct constructors, enum variant constructors, associated constants and functions, and local bindings; and the macro namespace holds macro_rules declarations, procedural macros and attributes. A use of a name looks in the namespace the position requires, so the same spelling can exist in more than one namespace without conflict - and, conversely, a name that exists only in the type or macro namespace does not become available where a value is required.
That split explains which names do have a value-namespace entry and which do not. A tuple struct and a tuple variant introduce a constructor in the value namespace, so their names can be called and can even be used as function values. A braced struct introduces no such constructor: its values are made with a struct expression, a path followed by braces holding a value for each field, as the Reference on struct expressions describes, and as the Book shows when it creates an instance by stating the struct name and adding curly brackets with key: value pairs. A unit struct and a unit variant do introduce a constant in the value namespace, so their bare names are values. An enum name itself introduces neither: only its variants do, each through its own constructor or constant. A module introduces no value at all; the values inside it - constants, statics and functions - are reached with a path, a sequence of segments separated by ::, as the Reference on paths defines it, not with the dot that reads a field off a value. And a macro is invoked through its macro-namespace syntax, some_extension!(...) in the Reference on macros wording - without the !, the spelling is read as a function name in the value namespace, where no such function exists.
Two consequences follow for fixing the error. First, the fix is never to rename or to import something: the name is already found, and the diagnostic's note - "a struct named Point exists in another namespace", "a module named a exists in another namespace", "a macro named println exists in another namespace" - is the compiler confirming that. What has to change is the form of the expression, so it asks the right namespace for the right kind of thing. Second, the correct form depends on the kind of item, not on the position: parentheses for tuple constructors, braces with field names for braced structs and struct-like variants, a bare name only for unit structs, unit variants, constants and functions, :: for anything inside a module or an enum, and ! for a macro. Reading the item's definition tells you which form applies before the diagnostic's help text does.
How to read the diagnostic
The header names what the position needed and, in the current compiler wording, what it could not find there: "cannot find value Point in this scope", "cannot find function, tuple struct or tuple variant Point in this scope", "cannot find value a in this scope", "cannot find function println in this scope". Read those first words as the position's requirement, not as a claim that the name is missing - the note below the span then states where the name actually lives, in the form "a struct named Point exists in another namespace" or "an enum named Shape exists in another namespace". A name that does not exist at all is a different error, E0425, covered by the E0425 guide.
The caret span marks the exact expression that asked the wrong namespace, and the help text usually names the repair in one line: "use struct literal syntax instead", "use the path separator to refer to an item", "use ! to invoke the macro", or a suggested variant such as Shape::Square. Those helps are reliable in this error family because the compiler has already identified both sides - the item you named and the kind of use you attempted - so the help is a translation of that use into the item's own syntax, not a guess. When the help offers two variants, as it does for an enum, either one resolves the namespace error; which value the program should hold is the remaining decision, and it belongs to the program, not to the diagnostic.
The first failure: a braced struct called with parentheses
A braced struct - one defined with named fields in braces - has no constructor function, so calling its name with parentheses asks the value namespace for a callable that was never introduced there:
struct Point { x: i32, y: i32 }
fn main() { let p = Point(3, 4); println!("{} {}", p.x, p.y); }
$ rustc --edition 2021 fail_braced_paren.rs -o fail_braced_paren
error[E0423]: cannot find function, tuple struct or tuple variant `Point` in this scope
--> fail_braced_paren.rs:2:21
|
1 | struct Point { x: i32, y: i32 }
| ------------------------------- `Point` defined here
2 | fn main() { let p = Point(3, 4); println!("{} {}", p.x, p.y); }
| ^^^^^^^^^^^
|
= note: a struct named `Point` exists in another namespace
help: use struct literal syntax instead of calling
|
2 - fn main() { let p = Point(3, 4); println!("{} {}", p.x, p.y); }
2 + fn main() { let p = Point{x: 3, y: 4}; println!("{} {}", p.x, p.y); }
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0423`.
The note confirms the split: a struct named Point exists, in another namespace - the type namespace. The parentheses form belongs to tuple structs, whose names are constructors. The fix keeps the same two values and changes only the form, to a struct literal with braces and the field names the definition declares, as the help suggests:
struct Point { x: i32, y: i32 }
fn main() { let p = Point { x: 3, y: 4 }; println!("{} {}", p.x, p.y); }
$ rustc --edition 2021 fix_braced_paren.rs -o fix_braced_paren
$ ./fix_braced_paren
3 4
The output is 3 4, the two fields as stored. The same repair applies wherever the call form appears - in a let, as an argument, or as a return expression: the syntax is a property of the struct kind, not of the position.
The second failure: a braced struct used as a bare value
Removing the parentheses does not make the bare name a value. A braced struct name on its own still names only the type, so a position that needs a value - here the right-hand side of a let that goes on to read the fields - finds nothing in the value namespace:
struct Point { x: i32, y: i32 }
fn main() { let p = Point; println!("{} {}", p.x, p.y); }
$ rustc --edition 2021 fail_braced_bare.rs -o fail_braced_bare
error[E0423]: cannot find value `Point` in this scope
--> fail_braced_bare.rs:2:21
|
1 | struct Point { x: i32, y: i32 }
| ------------------------------- `Point` defined here
2 | fn main() { let p = Point; println!("{} {}", p.x, p.y); }
| ^^^^^ help: use struct literal syntax instead: `Point { x: val, y: val }`
|
= note: a struct named `Point` exists in another namespace
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0423`.
The help this time offers the literal directly, Point { x: val, y: val }. The contrast with a tuple struct is the point to keep: a tuple struct's bare name is its constructor function, a real value, while a braced struct has no constructor at all, so there is nothing for the bare name to denote. The fix constructs the value with braces:
struct Point { x: i32, y: i32 }
fn main() { let p = Point { x: 3, y: 4 }; println!("{} {}", p.x, p.y); }
$ rustc --edition 2021 fix_braced_bare.rs -o fix_braced_bare
$ ./fix_braced_bare
3 4
The output is 3 4. A bare name is a value only when the item introduces one - a unit struct, a unit variant, a constant, a static, or a constructor - and a braced struct introduces none of those under its own name.
The third failure: a generic braced struct called with parentheses
Generic parameters change nothing about the constructor question. Pair<T> is a braced struct for every T, so calling Pair(1, 2) fails for the same reason as the non-generic case, with the same note:
struct Pair<T> { first: T, second: T }
fn main() { let p = Pair(1, 2); println!("{} {}", p.first, p.second); }
$ rustc --edition 2021 fail_generic_paren.rs -o fail_generic_paren
error[E0423]: cannot find function, tuple struct or tuple variant `Pair` in this scope
--> fail_generic_paren.rs:2:21
|
1 | struct Pair<T> { first: T, second: T }
| -------------------------------------- `Pair` defined here
2 | fn main() { let p = Pair(1, 2); println!("{} {}", p.first, p.second); }
| ^^^^^^^^^^
|
= note: a struct named `Pair` exists in another namespace
help: use struct literal syntax instead of calling
|
2 - fn main() { let p = Pair(1, 2); println!("{} {}", p.first, p.second); }
2 + fn main() { let p = Pair{first: 1, second: 2}; println!("{} {}", p.first, p.second); }
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0423`.
The values 1 and 2 determine T = i32 in the fix just as they would have in the call; what they cannot do is supply the field names, because a braced struct literal names its fields explicitly - first and second here - in any order. The fix writes the literal with those names:
struct Pair<T> { first: T, second: T }
fn main() { let p = Pair { first: 1, second: 2 }; println!("{} {}", p.first, p.second); }
$ rustc --edition 2021 fix_generic_paren.rs -o fix_generic_paren
$ ./fix_generic_paren
1 2
The output is 1 2. When a generic braced struct appears in code migrated from a tuple-struct design, this is the usual shape of the break: the call sites all need braces and field names, not just a change at the definition.
The fourth failure: a braced struct bare in return position
Return position is a value position like any other. A function declared to return Point must end with a Point value; ending with the bare name Point hands back the type name instead, and the error fires at that expression even though the return type is spelled with the same word:
struct Point { x: i32, y: i32 }
fn get() -> Point { Point }
fn main() { let p = get(); println!("{} {}", p.x, p.y); }
$ rustc --edition 2021 fail_braced_return.rs -o fail_braced_return
error[E0423]: cannot find value `Point` in this scope
--> fail_braced_return.rs:2:21
|
1 | struct Point { x: i32, y: i32 }
| ------------------------------- `Point` defined here
2 | fn get() -> Point { Point }
| ^^^^^ help: use struct literal syntax instead: `Point { x: val, y: val }`
|
= note: a struct named `Point` exists in another namespace
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0423`.
The identity of spelling is what makes this family easy to misread: -> Point uses the name in the type namespace, correctly, and the body must use a different form of the same name to make a value. The Book's struct chapter makes the same distinction when it constructs the returned instance as the last expression of the function body. The fix constructs the value in that last expression:
struct Point { x: i32, y: i32 }
fn get() -> Point { Point { x: 3, y: 4 } }
fn main() { let p = get(); println!("{} {}", p.x, p.y); }
$ rustc --edition 2021 fix_braced_return.rs -o fix_braced_return
$ ./fix_braced_return
3 4
The output is 3 4, printed from the value get returned. Any position that promises a value of a braced-struct type - a return expression, a match arm, an array element - needs the literal, never the bare type name.
The fifth failure: an enum name used as a value
An enum name names the type that all its variants share; it is not itself one of the values. Using Shape where a value is needed therefore finds an enum in another namespace and no value in this one - the error index states this case directly: enums are types and cannot be used directly as values:
enum Shape { Circle(i32), Square }
fn main() { let s = Shape; }
$ rustc --edition 2021 fail_enum_bare.rs -o fail_enum_bare
error[E0423]: cannot find value `Shape` in this scope
--> fail_enum_bare.rs:2:21
|
2 | fn main() { let s = Shape; }
| ^^^^^
|
= note: an enum named `Shape` exists in another namespace
note: the enum is defined here
--> fail_enum_bare.rs:1:1
|
1 | enum Shape { Circle(i32), Square }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: you might have meant to use the following enum variant
|
2 | fn main() { let s = Shape::Square; }
| ++++++++
help: alternatively, the following enum variant is available
|
2 - fn main() { let s = Shape; }
2 + fn main() { let s = (Shape::Circle(/* fields */)); }
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0423`.
The help names the missing step: pick a variant. Shape::Circle(3) reaches the variant's constructor through the enum name with a path, and Shape::Square would be the variant's constant. The fix names the tuple variant and supplies its field:
#[allow(dead_code)]
enum Shape { Circle(i32), Square }
fn main() { let s = Shape::Circle(3); match s { Shape::Circle(r) => println!("{}", r), Shape::Square => println!("square"), } }
$ rustc --edition 2021 fix_enum_bare.rs -o fix_enum_bare
$ ./fix_enum_bare
3
The output is 3, the radius carried by the Circle variant. The general form is always Enum::Variant - the enum name alone never denotes a value, however obvious the intended variant feels from context.
The sixth failure: Option::<i32> used as a value
Adding a type argument does not turn an enum name into a value. Option::<i32> is a fully specified type - the turbofish pins down T = i32 - but a type, however specific, still lives in the type namespace, so using it as the right-hand side of a let is the enum case again, in the exact form the error index gives for it:
fn main() { let x = Option::<i32>; println!("{:?}", x); }
$ rustc --edition 2021 fail_option_bare.rs -o fail_option_bare
error[E0423]: cannot find value `Option` in this scope
--> fail_option_bare.rs:1:21
|
1 | fn main() { let x = Option::<i32>; println!("{:?}", x); }
| ^^^^^^
|
= note: an enum named `Option` exists in another namespace
help: you might have meant to use the following enum variant
|
1 - fn main() { let x = Option::<i32>; println!("{:?}", x); }
1 + fn main() { let x = std::option::Option::None; println!("{:?}", x); }
|
help: alternatively, the following enum variant is available
|
1 - fn main() { let x = Option::<i32>; println!("{:?}", x); }
1 + fn main() { let x = (std::option::Option::Some(/* fields */)); println!("{:?}", x); }
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0423`.
The value has to come from a variant: None, or Some carrying a value. The fix states the type once, as an annotation, and lets the variant supply the value:
fn main() { let x: Option<i32> = None; println!("{:?}", x); }
$ rustc --edition 2021 fix_option_bare.rs -o fix_option_bare
$ ./fix_option_bare
None
The output is None. Keep the two uses of the spelling separate: Option<i32> in a type position describes the slot, and None or Some(..) in a value position fills it - the guide for mismatched types, E0308 covers the neighboring case where a value is present but its type is the wrong one.
The seventh failure: a module accessed with a dot
A dot reads a field or calls a method on a value; it does not reach inside a module. a is a module, so a.I tries to use the module name itself as a value first, and fails there - this is the shape the error codes index itself uses for the value-expected half of E0423:
pub mod a { pub const I: i32 = 1; }
fn h1() -> i32 { a.I }
fn main() { println!("{}", h1()); }
$ rustc --edition 2021 fail_module_dot.rs -o fail_module_dot
error[E0423]: cannot find value `a` in this scope
--> fail_module_dot.rs:2:18
|
2 | fn h1() -> i32 { a.I }
| ^
|
= note: a module named `a` exists in another namespace
help: use the path separator to refer to an item
|
2 - fn h1() -> i32 { a.I }
2 + fn h1() -> i32 { a::I }
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0423`.
Items inside a module are named with a path, whose segments are separated by :: - the help says so in one line, "use the path separator to refer to an item". The constant I is a value-namespace item; the path a::I is how a value position names it. The fix changes only the separator:
pub mod a { pub const I: i32 = 1; }
fn h1() -> i32 { a::I }
fn main() { println!("{}", h1()); }
$ rustc --edition 2021 fix_module_dot.rs -o fix_module_dot
$ ./fix_module_dot
1
The output is 1, the constant's value. The same separator rule covers functions, statics and types inside a module, and variants inside an enum - a dot after a module or enum name is always this error waiting to happen.
The eighth failure: a macro called without !
Macros live in the macro namespace and are invoked with an exclamation mark. Without it, println is read as a function name in the value namespace, where no function by that name exists - the error index calls out this case by name, as a common way to produce this error:
fn main() { println("hello"); }
$ rustc --edition 2021 fail_macro_no_bang.rs -o fail_macro_no_bang
error[E0423]: cannot find function `println` in this scope
--> fail_macro_no_bang.rs:1:13
|
1 | fn main() { println("hello"); }
| ^^^^^^^ not found in this scope
|
= note: a macro named `println` exists in another namespace
help: use `!` to invoke the macro
|
1 | fn main() { println!("hello"); }
| +
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0423`.
The note locates the name - a macro named println exists in another namespace - and the help supplies the one-character repair, "use ! to invoke the macro". Nothing about the argument changes: "hello" was a valid argument for the macro all along. The fix adds the mark:
fn main() { println!("hello"); }
$ rustc --edition 2021 fix_macro_no_bang.rs -o fix_macro_no_bang
$ ./fix_macro_no_bang
hello
The output is hello. Every macro invocation has the same requirement - vec!, format!, write! and your own macro_rules macros alike - and a missing ! always surfaces as this namespace error rather than as a macro error, because the macro is never reached.
The fixes in reach order
- The note says a struct exists in another namespace and the expression called it with parentheses: a braced struct called as if it were a tuple struct - rewrite the call as a struct literal, with braces and every field name.
- The note says a struct exists in another namespace and the expression was the bare name: a braced struct used as a value - construct it with braces and field names; a braced struct's name alone is never a value.
- The called or bare name is generic, such as
Pair(1, 2): the same braced-struct repair - generic parameters do not create a constructor, and the literal still names its fields. - The bare name sits in return position or another promised-value position: construct the value there - the return type's spelling being the same word does not make the name an expression.
- The note says an enum exists in another namespace: an enum name used as a value - name a variant,
Enum::Variant, supplying its fields if it has any. - The expression is an enum name with a type argument, such as
Option::<i32>: a type is still not a value - annotate the binding with the type and assign a variant,NoneorSome(..). - The note says a module exists in another namespace and the expression used a dot: a module reached with field syntax - replace the dot with the path separator,
a::I. - The note says a macro exists in another namespace: a macro invoked as a function - add the exclamation mark,
println!(...).
Traps
- A tuple struct written with braces and a positional field compiles - it is not an E0423 family. The Reference on struct expressions allows the field names in a braced literal to be decimal integers naming tuple indices, so
Wrapper { 0: 5 }constructs the same value asWrapper(5):
struct Wrapper(i32);
fn main() { let w = Wrapper { 0: 5 }; println!("{}", w.0); }
$ rustc --edition 2021 probe_tuple_braced_index.rs -o probe_tuple_braced_index
$ ./probe_tuple_braced_index
5
5. This is the mirror image of the first family: parentheses on a braced struct fail because that struct has no constructor, while braces on a tuple struct succeed because the braced literal is a struct expression whose fields happen to be indices. Do not "fix" the braced tuple form on sight - it is legal, if unusual.
- A bare tuple-struct name followed by a field read is E0609, not E0423. The bare name Wrapper is a value - the constructor function - so no namespace error fires; the failure comes one step later, when .0 is read off a function type, which has no fields:struct Wrapper(i32);
fn main() { let w = Wrapper; println!("{}", w.0); }
$ rustc --edition 2021 probe_tuple_bare_e0609.rs -o probe_tuple_bare_e0609
error[E0609]: no field `0` on type `fn(i32) -> Wrapper {Wrapper}`
--> probe_tuple_bare_e0609.rs:2:47
|
2 | fn main() { let w = Wrapper; println!("{}", w.0); }
| ^ unknown field
|
help: use parentheses to construct this tuple struct
|
2 | fn main() { let w = Wrapper; println!("{}", w(/* i32 */).0); }
| +++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0609`.
The header reads "no field 0 on type fn(i32) -> Wrapper", and that function type in the header is the tell: the name denoted the constructor, exactly as the struct-expression Reference describes when it notes that a tuple struct's name can be taken as the function that creates the value. The error codes index defines E0609 as an attempt to access a nonexistent field. The repair is to call the constructor first, Wrapper(5).0 - the opposite direction from the braced families, where the name must not be called at all.
- Calling a unit struct is E0618, not E0423. Marker is a unit struct, so its bare name is a constant value in the value namespace - using it bare would compile - but it is not a function, so calling it with an argument fails as a call of a non-function:
struct Marker;
fn main() { let m = Marker(5); }
$ rustc --edition 2021 probe_unit_call_e0618.rs -o probe_unit_call_e0618
error[E0618]: expected function, found `Marker`
--> probe_unit_call_e0618.rs:2:21
|
1 | struct Marker;
| ------------- `Marker` defined here
2 | fn main() { let m = Marker(5); }
| ^^^^^^---
| |
| call expression requires function
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0618`.
The header reads "expected function, found Marker". The error codes index defines E0618 as an attempt to call something that is not a function or method. The three struct kinds separate cleanly here: a braced struct's name is a type only, a tuple struct's name is a callable constructor, and a unit struct's name is a non-callable value - each misuse lands on a different code.
- A bare struct-like enum variant is E0533, not E0423. Event::Click names a variant that carries named fields, so like a braced struct it has no constant or constructor usable as the bare path - but because the path itself resolves to the variant, the compiler reports the variant-specific code instead of the namespace code:
enum Event { Click { x: i32, y: i32 }, Scroll }
fn main() { let e = Event::Click; }
$ rustc --edition 2021 probe_struct_variant_bare_e0533.rs -o probe_struct_variant_bare_e0533
error[E0533]: expected value, found struct variant `Event::Click`
--> probe_struct_variant_bare_e0533.rs:2:21
|
2 | fn main() { let e = Event::Click; }
| ^^^^^^^^^^^^ not a value
|
help: you might have meant to create a new value of the struct
|
2 | fn main() { let e = Event::Click { x: /* value */, y: /* value */ }; }
| ++++++++++++++++++++++++++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0533`.
The header reads "expected value, found struct variant Event::Click". The repair matches the braced-struct repair: construct it, Event::Click { x: 1, y: 2 }. Compare the fifth family, where the enum name itself was used: the enum name is a type-namespace item and draws E0423, while a struct-like variant reached by its full path draws E0533 - the position of the mistake, before or after the ::, decides the code.
- A tuple struct written with a named braced field is E0560, not E0423. Wrapper { x: 5 } is a well-formed struct expression in form - braces are allowed, as the first trap shows - but a tuple struct has no field named x; its only field is the index 0:
struct Wrapper(i32);
fn main() { let w = Wrapper { x: 5 }; println!("{}", w.0); }
$ rustc --edition 2021 probe_tuple_named_field_e0560.rs -o probe_tuple_named_field_e0560
error[E0560]: struct `Wrapper` has no field named `x`
--> probe_tuple_named_field_e0560.rs:2:31
|
1 | struct Wrapper(i32);
| ------- `Wrapper` defined here
2 | fn main() { let w = Wrapper { x: 5 }; println!("{}", w.0); }
| ^ field does not exist
|
help: `Wrapper` is a tuple struct, use the appropriate syntax
|
2 - fn main() { let w = Wrapper { x: 5 }; println!("{}", w.0); }
2 + fn main() { let w = Wrapper(/* i32 */); println!("{}", w.0); }
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0560`.
The header reads "struct Wrapper has no field named x", and the error codes index defines E0560 as an unknown field specified in a structure. Use the index, Wrapper { 0: 5 }, or the call form, Wrapper(5). This trap and the first one are the same program with one token changed - the field key - which is why the braced tuple form belongs in traps and decisions, never in a list of E0423 causes.
- A bare tuple-variant name compiles as the constructor function value. Shape::Circle without parentheses is not a Shape value and not an error: it is the function that builds one, and calling that binding produces the variant:
#[allow(dead_code)]
enum Shape { Circle(i32), Square }
fn main() { let f = Shape::Circle; let s = f(3); match s { Shape::Circle(r) => println!("{}", r), Shape::Square => println!("square"), } }
$ rustc --edition 2021 probe_tuple_variant_bare.rs -o probe_tuple_variant_bare
$ ./probe_tuple_variant_bare
3
The output is 3, printed after the stored constructor f is called with 3. This is the behavior that makes the enum family precise: an enum name used bare is E0423 because the enum introduces no value-namespace entry of its own, while a tuple variant's name does - its constructor - so the variant path can stand alone where the enum name cannot. A unit variant goes one step further and its bare path is the value itself, not a function.
Decision summary
- The header says "cannot find value" or "cannot find function, tuple struct or tuple variant" and a note says the named struct exists in another namespace (E0423): a braced struct used as a value or called - construct it with braces and field names.
- The header names a generic braced struct in the same wording (E0423): the same cause - generic parameters create no constructor; write the literal with its field names.
- The header says "cannot find value" for an enum name, with a note that an enum exists in another namespace (E0423): name a variant -
Enum::Variant- instead of the enum. - The expression is an enum name with a type argument, such as
Option::<i32>(E0423): a specified type is still a type - assign a variant and put the type in an annotation if it is needed. - The header says "cannot find value" for a module name, with a note that a module exists in another namespace (E0423): replace the dot with
::and name the item inside the module. - The header says "cannot find function" for a macro name, with a note that a macro exists in another namespace (E0423): add the exclamation mark.
- The header says "cannot find value" with no namespace note, or the name is simply not defined (E0425): the name itself is missing or misspelled - the subject of the E0425 guide - not a namespace mismatch.
- A braced tuple-struct literal with an index field,
Wrapper { 0: 5 }, compiles: no error - the index is a legal field key in a struct expression. - The header says "no field
0on typefn(i32) -> Wrapper" (E0609): a bare tuple-struct name denoted its constructor function - call it to make the value before reading fields. - The header says "expected function, found" a unit struct's name (E0618): a unit struct's name is a value, not a callable - use it bare, without parentheses or arguments.
- The header says "expected value, found struct variant" (E0533): a struct-like variant used bare - construct it with braces and its field names.
- The header says a tuple struct "has no field named" the key used (E0560): the braced form used a name where the tuple struct has only indices - use the index or the call form.
- A bare tuple-variant path, such as
Shape::Circle, compiles as a function value: no error - it is the variant's constructor, callable to produce the variant's value. - The header says "mismatched types" (E0308): a value is present but has the wrong type - no namespace question at all, the subject of the E0308 guide.
- The header says "no method named ... found" (E0599): a method call on a value whose type provides no such method - the subject of the E0599 guide.
Checklist
- The namespace note read before any edit: "exists in another namespace" confirms the name is spelled right and in scope - the expression's form is the defect, so no renaming, importing or defining is part of the fix.
- The item kind identified from its definition: braced struct, tuple struct, unit struct, enum, variant of each kind, module, constant, function or macro - the kind, not the position, decides the correct form.
- Braced structs and struct-like variants constructed with braces and field names, never called with parentheses and never used bare.
- Tuple structs and tuple variants called with parentheses - or taken bare only when the constructor function itself is what the code means to pass or store.
- Unit structs and unit variants used bare, never called.
- Enum values always reached through a variant: the enum name alone, with or without a type argument, is a type and nothing more.
- Items inside modules and enums reached with
::paths, never with a dot; dots are for fields and methods on values already constructed. - Macros invoked with
!; a "cannot find function" header naming a known macro is this error, not a missing import. - After the form is changed, the program compiled again and run: the fix is finished only when the constructed value is the one the program uses and the output is the value the program was written to produce.
Related guides on this site
- E0425 Cannot Find Value Fix
- Fix Rust E0308 "mismatched types" — Convert the Value, Fix the Signature, or Give Both Sides One Type
- Fix Rust E0515 "cannot return value referencing local variable" — a Local String, a Local Number, a Local Vec Slice, and a Struct Wrapping a Local
- Fix Rust E0382 "borrow of moved value" — Borrow Instead of Moving, Return the Value, or Clone on Purpose
Sources
- Rust, Error codes index: E0423 - the definition of the error: an identifier was used like a function name, or a value was expected and the identifier exists but belongs to a different namespace - with the braced struct called as
Foo(), the macro called without the trailing!, the module examplea.Icorrected toa::I, and the statement that enums are types and cannot be used directly as values, shown withOption::<i32>. - The Rust Reference, Namespaces - the type, value and macro namespaces and their members: structs, enums and modules in the type namespace; functions, constants, statics, struct constructors and enum variant constructors in the value namespace; macros in the macro namespace.
- The Rust Reference, Struct expressions - a struct expression creates a struct, enum or union value from a path followed by field values in braces; tuple structs and tuple variants are typically instantiated with a call expression referring to the constructor in the value namespace, unit structs and unit variants with a path expression referring to the constant in the value namespace, and field names in a braced literal may be decimal integers naming tuple indices.
- The Rust Reference, Paths - a path is a sequence of one or more segments separated by
::, used to refer to items, values, types, macros and attributes - the form that reaches a constant inside a module or a variant inside an enum. - The Rust Reference, Macros - macros are invoked through a consistent syntax,
some_extension!(...), and a macro invocation expands at compile time - the exclamation mark is part of the invocation form, not an optional decoration. - The Rust Programming Language, Defining and Instantiating Structs - creating an instance by stating the struct name and adding curly brackets with
key: valuepairs for the fields, constructing an instance as the last expression of a function to return it, and the tuple and unit-like struct forms and how each is instantiated. - Rust, Error codes index: E0609 - the neighboring field error: an attempt to access a nonexistent field in a struct - the code a field read on a tuple-struct constructor function produces.
- Rust, Error codes index: E0618 - the neighboring call error: an attempt to call something that is not a function or a method - the code calling a unit struct produces.
- Rust, Error codes index: E0560 - the neighboring field-name error: an unknown field was specified into a structure - the code a named braced field on a tuple struct produces.
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.