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
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
- E0061this function takes N arguments but M were supplied
- E0412cannot find type in this scope
- E0515cannot return reference to local variable
- E0728await is only allowed inside async functions and blocks
- E0605non-primitive cast
- E0606casting `&u8` as `u32` is invalid
- E0627yield expression outside of coroutine literal
- E0628too many parameters for a coroutine (expected 0 or 1 parameters)
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?