Email me

Rust errors / Names, paths and imports

Rust compiler error · checked with rustc 1.99.0

Rust error E0423: cannot find function, tuple struct or tuple variant `Foo` in this scope

What it meansAn identifier was used like a function name or a value was expected and the identifier exists but it belongs to a different namespace.

What rustc prints

error[E0423]: cannot find function, tuple struct or tuple variant `Foo` in this scope
 --> main.rs:5:9
  |
3 | struct Foo { a: bool };
  | ---------------------- `Foo` defined here
4 |
5 | let f = Foo();
  |         ^^^^^ help: use struct literal syntax instead: `Foo { a: val }`
  |
  = note: a struct named `Foo` exists in another namespace

Real output of rustc 1.99.0 compiling the official example below (2021 edition). Your names and line numbers will differ; the first line is the part to match.

E0423Names, paths and imports
Activein rustc 1.99.0
7related errors linked below

The compiler team's explanation

An identifier was used like a function name or a value was expected and the identifier exists but it belongs to a different namespace.

Erroneous code example:

struct Foo { a: bool };

let f = Foo();
// error: expected function, tuple struct or tuple variant, found `Foo`
// `Foo` is a struct name, but this expression uses it like a function name

Please verify you didn't misspell the name of what you actually wanted to use here. Example:

fn Foo() -> u32 { 0 }

let f = Foo(); // ok!

It is common to forget the trailing ! on macro invocations, which would also yield this error:

println("");
// error: expected function, tuple struct or tuple variant,
// found macro `println`
// did you mean `println!(...)`? (notice the trailing `!`)

Another case where this error is emitted is when a value is expected, but something else is found:

pub mod a {
    pub const I: i32 = 1;
}

fn h1() -> i32 {
    a.I
    //~^ ERROR expected value, found module `a`
    // did you mean `a::I`?
}

Enum types used as values

Enums are types and cannot be used directly as values.

fn main(){
    let x = Option::<i32>;
    //~^ ERROR expected value,found enum `Option`
}

From rustc --explain E0423 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.

Related errors

All 518 Rust error codes · Rust crate data · Glossary

Up next

Often hit nextE0425: cannot find value in this scopeA related error from the same family.Read it next →

Did this answer your question?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ