Email me

Rust errors / Everything else

Rust compiler error · checked with rustc 1.99.0

Rust error E0618: expected function, found

What it meansSomething is used like a function (name(...)) but is not one: a unit enum variant, a struct, a number or a variable.

What rustc prints

error[E0618]: expected function, found enum variant `X::Entry`
 --> main.rs:7:1
  |
4 |     Entry,
  |     ----- enum variant `X::Entry` defined here
...
7 | X::Entry(); // error: expected function, tuple struct or tuple variant,
  | ^^^^^^^^--
  | |
  | call expression requires function
  |
help: `X::Entry` is a unit enum variant, and does not take parentheses to be constructed
  |
7 - X::Entry(); // error: expected function, tuple struct or tuple variant,
7 + X::Entry; // error: expected function, tuple struct or tuple variant,
  |

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.

Why it happens

  • Calling a unit variant: State::Idle().
  • A local variable shadows a function with the same name.

How to fix it

1. Drop the parentheses for unit variants

let s = State::Idle;

2. Rename the shadowing variable

let total_count = count(&items);  // not let count = count(&items) then count(...)

Other wordings of this error

expected function, found, call expression requires function

E0618Everything else
Activein rustc 1.99.0
8related errors linked below

The compiler team's explanation

Attempted to call something which isn't a function nor a method.

Erroneous code examples:

enum X {
    Entry,
}

X::Entry(); // error: expected function, tuple struct or tuple variant,
            // found `X::Entry`

// Or even simpler:
let x = 0i32;
x(); // error: expected function, tuple struct or tuple variant, found `i32`

Only functions and methods can be called using (). Example:

// We declare a function:
fn i_am_a_function() {}

// And we call it:
i_am_a_function();

From rustc --explain E0618 (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 nextE0061: this function takes N arguments but M were suppliedA 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