Rust

E0618 Expected Function Fix

Call parentheses are not a general way to use a value: they belong after a function, a closure, a function pointer, or a constructor. E0618 is the compiler reporting that the expression before the parentheses has a type with no call behind it - an integer, a string, a struct instance, a collection, the result a function already returned. This guide separates the eleven shapes that produce it - scalar, string, struct instance, shadowed function name, unit variant, bool, vector, returned value, tuple, reference, and indexing result - and matches each one to its repair: use the value as the value it already is, call a method by its name, rename the local that hides the function, or drop the parentheses the variant never took.

Written November 25, 2026 · Tested with Rust 1.99.1 · 27 min read

By the end of this guide
  • The rule underneath: what can be called
  • How to read the diagnostic
  • The first failure: an integer variable
  • The second failure: a String

Written November 25, 2026

Tested with Rust 1.99.1

What this guide is

Error E0618 is a call placed after something that cannot be called. The error codes index defines it in one line - attempted to call something which is not a function nor a method - and gives two examples: a unit enum variant written with parentheses, and an i32 variable called as x(). The diagnostic names the actual type it found in place of a function - "expected function, found i32", "found String", "found Point" - so the first step with any E0618 is to read that type: it says what the expression before the parentheses really is, and the repair follows from it.

The forms in this guide each reproduce E0618 with a small, complete program, and each puts the parentheses after a different kind of value: an integer variable, a String, a struct instance, a function name shadowed by a local variable, a unit enum variant, a bool, a Vec, the value a function call already returned, a tuple, a reference, and an indexing result. Most of the fixes delete the call rather than repair it, because most E0618 failures are not broken calls at all: they are finished values - a number already computed, an object already constructed - with a pair of parentheses left after them, usually carried over from the line that produced the value or from a language where the same syntax reads a property or invokes a default. Where a call genuinely was intended, the fix names the callable thing - a method, a renamed function, a constructor written in its own form.

Several neighboring results are not E0618 and are worked only in their own sections below. Closures, function pointers, functions returning closures, tuple struct constructors, and tuple variant constructors are all callable, and calling them compiles. A struct field written with call parentheses is not E0618 at all - the parser reads it as a method call and the error is E0599 - and a callable called with the wrong number of arguments is E0057 or E0061, because the callee was a function and only the argument list was wrong.

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: what can be called

The call expressions section of the Reference describes a call as a function operand followed by a parenthesized list of argument operands, and adds the extension that makes closures work: for non-function types, the expression f(...) uses the method of one of the Fn, FnMut, or FnOnce traits, matched to how the value is borrowed - or, for an async closure, one of the corresponding AsyncFn, AsyncFnMut, or AsyncFnOnce traits, whose call returns a future. That, with the constructors below, is the list of what may stand before the parentheses. A function item itself, a function pointer, or a value whose type implements one of the Fn traits - a closure, in practice - can be called. A tuple struct constructor and a tuple enum variant constructor can also be called, because each is a function in value form: Pair(1, 2) and E::V(3) below are calls to constructors, which is why they compile while the unit variant in the fifth family, which takes no fields and has no constructor call form, does not.

Everything else with parentheses after it is E0618, whatever it looks like. An integer is data. A String is data. A struct instance is the finished product of a constructor call that already happened, at the Point { x: 1, y: 2 } expression, and calling the product does not call anything again. The function pointer documentation states the contrast from the callable side: function pointers are pointers that point to code, not data, and they can be called just like functions. E0618 is that sentence read from the other side - the operand pointed at data, and there was no code behind it for the call to run.

One boundary in the list surprises most people, and the fourth family is built on it: what stands before the parentheses is a name, and a name in an expression means the innermost binding of that name. A local variable named like a function does not leave the function reachable under the same spelling - the local shadows it, the expression denotes the local, and the call is judged against the local's type. The compiler's diagnostic for that family says so explicitly, noting the function of the same name that is available but shadowed.

How to read the diagnostic

Every failure in the eleven families prints the same shape of output. The first family's, in full:

Terminal
$ rustc --edition 2021 fail_int.rs -o fail_int
error[E0618]: expected function, found `i32`
 --> fail_int.rs:3:5
  |
2 |     let x = 0i32;
  |         - `x` has type `i32`
3 |     x();
  |     ^--
  |     |
  |     call expression requires function

error: aborting due to 1 previous error

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

Read it in order. The header names the type that was found where a function was expected - that type is the diagnosis, and the families below are organized by exactly those types. The span underlines the callee expression and adds the note "call expression requires function" beneath it. Where the callee is a local binding, a second note names the binding and its type - "x has type i32" - which is the line to compare against what the code intended to call. Two families add more: the shadowing family's diagnostic points back at the function definition and says it is shadowed by the local binding, and the unit variant family's carries a help that rewrites the expression without the parentheses. When either of those notes appears, the fix is already written in the output.

That shape is also the fastest way to separate E0618 from its neighbors before touching code. If the header says "expected function", the callee is not callable and this guide applies. If it says "no method named" (E0599), the parentheses after a dot were read as a method call - the traps below. If it says a function "takes N arguments but M arguments were supplied" (E0057, E0061), the callee was callable all along and only the argument list needs work.

The first failure: an integer variable

A program that calls an integer variable - the simpler of the two examples in the error codes index:

Rust
fn main() {
    let x = 0i32;
    x();
}
Terminal
$ rustc --edition 2021 fail_int.rs -o fail_int
error[E0618]: expected function, found `i32`
 --> fail_int.rs:3:5
  |
2 |     let x = 0i32;
  |         - `x` has type `i32`
3 |     x();
  |     ^--
  |     |
  |     call expression requires function

error: aborting due to 1 previous error

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

The value was already the answer. Nothing needs calling - the fix uses the variable as the integer it is:

Rust
fn main() {
    let x = 0i32;
    println!("{}", x);
}
Terminal
$ rustc --edition 2021 fix_int.rs -o fix_int
$ ./fix_int
0

The output is 0. The parentheses added nothing the variable did not already hold; in the failing program they asked the compiler to run a number as code, and the found type in the header, i32, is the variable's own type read back.

The second failure: a String

A program that calls a String:

Rust
fn main() {
    let s = String::from("hi");
    s();
}
Terminal
$ rustc --edition 2021 fail_string.rs -o fail_string
error[E0618]: expected function, found `String`
 --> fail_string.rs:3:5
  |
2 |     let s = String::from("hi");
  |         - `s` has type `String`
3 |     s();
  |     ^--
  |     |
  |     call expression requires function

error: aborting due to 1 previous error

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

If a call was intended, it was a method call, and method calls name the method after a dot. The fix asks the string for its length:

Rust
fn main() {
    let s = String::from("hi");
    println!("{}", s.len());
}
Terminal
$ rustc --edition 2021 fix_string_method.rs -o fix_string_method
$ ./fix_string_method
2

The output is 2, the length of "hi". A bare s() has no method name in it, so there was never a candidate operation for the compiler to run - String has many methods, and the call parentheses alone do not pick one. Writing the name, len, is the whole repair.

The third failure: a struct instance

A program that calls a struct instance it has just built:

Rust
struct Point {
    x: i32,
    y: i32,
}
fn main() {
    let p = Point { x: 1, y: 2 };
    p();
}
Terminal
$ rustc --edition 2021 fail_struct_instance.rs -o fail_struct_instance
error[E0618]: expected function, found `Point`
 --> fail_struct_instance.rs:7:5
  |
6 |     let p = Point { x: 1, y: 2 };
  |         - `p` has type `Point`
7 |     p();
  |     ^--
  |     |
  |     call expression requires function

error: aborting due to 1 previous error

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

The instance is a value, and its parts are reached by field access, not by a call. The fix reads the two fields:

Rust
struct Point {
    x: i32,
    y: i32,
}
fn main() {
    let p = Point { x: 1, y: 2 };
    println!("{} {}", p.x, p.y);
}
Terminal
$ rustc --edition 2021 fix_struct_field.rs -o fix_struct_field
$ ./fix_struct_field
1 2

The output is 1 2. The constructor call in this program already happened - Point { x: 1, y: 2 } is the call-shaped expression that produced the value - and p() tries to call the product of that construction. Where the intended operation is a behavior of the type rather than a field, the method form in the traps, s.get(), is the shape that compiles.

The fourth failure: a function name shadowed by a local

A program that declares a function and then reuses its name for a local variable, and calls the name:

Rust
fn foo() -> i32 {
    42
}
fn main() {
    let foo = 7;
    println!("{}", foo());
}
Terminal
$ rustc --edition 2021 fail_shadow_fn.rs -o fail_shadow_fn
error[E0618]: expected function, found `{integer}`
 --> fail_shadow_fn.rs:6:20
  |
1 | fn foo() -> i32 {
  | --------------- this function of the same name is available here, but it's shadowed by the local binding
...
5 |     let foo = 7;
  |         --- `foo` has type `{integer}`
6 |     println!("{}", foo());
  |                    ^^^--
  |                    |
  |                    call expression requires function

error: aborting due to 1 previous error

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

The diagnostic is the fullest of the eleven: it points at the function definition, notes that it is shadowed by the local binding, and reports the local's type, {integer}, as the found type. The fix renames the local, so the name denotes the function again:

Rust
fn foo() -> i32 {
    42
}
fn main() {
    let value = 7;
    println!("{} {}", foo(), value);
}
Terminal
$ rustc --edition 2021 fix_shadow_rename.rs -o fix_shadow_rename
$ ./fix_shadow_rename
42 7

The output is 42 7 - the function's return value first, then the renamed local's value. Both things the program wanted are still there; they simply cannot share one name in one scope, because an expression can only denote one of them. The trap below shows the same shadowing with a closure as the local, which compiles - and calls the closure, not the function.

The fifth failure: a unit enum variant with parentheses

A program that writes a unit variant with parentheses - the first example in the error codes index, whose wording the header follows here, "expected function, found enum variant":

Rust
enum X {
    Entry,
}
fn main() {
    let e = X::Entry();
    println!("{:?}", std::mem::discriminant(&e));
}
Terminal
$ rustc --edition 2021 fail_enum_unit.rs -o fail_enum_unit
error[E0618]: expected function, found enum variant `X::Entry`
 --> fail_enum_unit.rs:5:13
  |
2 |     Entry,
  |     ----- enum variant `X::Entry` defined here
...
5 |     let e = X::Entry();
  |             ^^^^^^^^--
  |             |
  |             call expression requires function
  |
help: `X::Entry` is a unit enum variant, and does not take parentheses to be constructed
  |
5 -     let e = X::Entry();
5 +     let e = X::Entry;
  |

error: aborting due to 1 previous error

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

A unit variant has no fields, so there is nothing for parentheses to carry and no constructor call to make. The compiler's help says it directly: a unit variant does not take parentheses to be constructed. The fix writes the variant bare:

Rust
#[derive(Debug)]
enum X {
    Entry,
}
fn main() {
    let e = X::Entry;
    println!("{:?}", e);
}
Terminal
$ rustc --edition 2021 fix_enum_unit.rs -o fix_enum_unit
$ ./fix_enum_unit
Entry

The output is Entry. Contrast the tuple variant in the callable section below: a variant with a field, E::V(3), is written with parentheses and compiles, because there the parentheses carry the field. Parentheses after a variant are a field list, not decoration - present exactly when the variant has fields.

The sixth failure: a bool

A program that calls a bool:

Rust
fn main() {
    let b = true;
    b();
}
Terminal
$ rustc --edition 2021 fail_bool.rs -o fail_bool
error[E0618]: expected function, found `bool`
 --> fail_bool.rs:3:5
  |
2 |     let b = true;
  |         - `b` has type `bool`
3 |     b();
  |     ^--
  |     |
  |     call expression requires function

error: aborting due to 1 previous error

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

The fix uses the flag as a value:

Rust
fn main() {
    let b = true;
    println!("{}", b);
}
Terminal
$ rustc --edition 2021 fix_bool.rs -o fix_bool
$ ./fix_bool
true

The output is true. This shape usually arrives from code translated out of a language or an API where a flag is read by calling it - a getter written as a call. In Rust a bool binding already is the flag; if the flag lives behind a method on some object, the method has a name and is called by that name, with the object before the dot.

The seventh failure: a Vec

A program that calls a Vec:

Rust
fn main() {
    let v = vec![1, 2, 3];
    v();
}
Terminal
$ rustc --edition 2021 fail_vec.rs -o fail_vec
error[E0618]: expected function, found `Vec<{integer}>`
 --> fail_vec.rs:3:5
  |
2 |     let v = vec![1, 2, 3];
  |         - `v` has type `Vec<{integer}>`
3 |     v();
  |     ^--
  |     |
  |     call expression requires function

error: aborting due to 1 previous error

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

As with the String family, a call on a collection means a method, named after the dot. The fix asks for the length:

Rust
fn main() {
    let v = vec![1, 2, 3];
    println!("{}", v.len());
}
Terminal
$ rustc --edition 2021 fix_vec_len.rs -o fix_vec_len
$ ./fix_vec_len
3

The output is 3. The found type is printed as Vec<{integer}> because the element type was inferred from the elements. Nothing about the collection is callable as a whole; its operations are its methods - len, push, indexing - each reached by name.

The eighth failure: the value a function already returned

A program that stores a function's return value and then calls the stored value:

Rust
fn get() -> i32 {
    7
}
fn main() {
    let y = get();
    y();
}
Terminal
$ rustc --edition 2021 fail_return_value.rs -o fail_return_value
error[E0618]: expected function, found `i32`
 --> fail_return_value.rs:6:5
  |
5 |     let y = get();
  |         - `y` has type `i32`
6 |     y();
  |     ^--
  |     |
  |     call expression requires function

error: aborting due to 1 previous error

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

The call already happened, on the line that produced the value: get() is the call, and y is its result, an i32. The fix uses the result:

Rust
fn get() -> i32 {
    7
}
fn main() {
    let y = get();
    println!("{}", y);
}
Terminal
$ rustc --edition 2021 fix_return_value.rs -o fix_return_value
$ ./fix_return_value
7

The output is 7. This is the most common E0618 shape in real code, because the failing line looks like a second step of a two-step call - as if get() fetched something callable and y() ran it. When a function really does return something callable, the second call is legal and looks identical; the callable section below shows make()() compiling, where make returns a closure. The difference is entirely in the return type: i32 here, a closure there.

The ninth failure: a tuple

A program that calls a tuple:

Rust
fn main() {
    let t = (1, 2);
    t();
}
Terminal
$ rustc --edition 2021 fail_tuple.rs -o fail_tuple
error[E0618]: expected function, found `({integer}, {integer})`
 --> fail_tuple.rs:3:5
  |
2 |     let t = (1, 2);
  |         - `t` has type `({integer}, {integer})`
3 |     t();
  |     ^--
  |     |
  |     call expression requires function

error: aborting due to 1 previous error

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

A tuple's elements are reached by position, with .0, .1, and so on. The fix reads both fields:

Rust
fn main() {
    let t = (1, 2);
    println!("{} {}", t.0, t.1);
}
Terminal
$ rustc --edition 2021 fix_tuple_fields.rs -o fix_tuple_fields
$ ./fix_tuple_fields
1 2

The output is 1 2. The found type is the pair's own type, ({integer}, {integer}). The confusion to separate this from is the tuple struct in the callable section: Pair(1, 2) compiles because Pair names a constructor; t here names a finished tuple value, and a value is not its type's constructor.

The tenth failure: a reference

A program that calls a reference to an integer:

Rust
fn main() {
    let x = 5;
    let r = &x;
    r();
}
Terminal
$ rustc --edition 2021 fail_ref_int.rs -o fail_ref_int
error[E0618]: expected function, found `&{integer}`
 --> fail_ref_int.rs:4:5
  |
3 |     let r = &x;
  |         - `r` has type `&{integer}`
4 |     r();
  |     ^--
  |     |
  |     call expression requires function

error: aborting due to 1 previous error

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

Dereferencing is not calling. The fix prints through the reference, which is what the binding already supports:

Rust
fn main() {
    let x = 5;
    let r = &x;
    println!("{}", r);
}
Terminal
$ rustc --edition 2021 fix_ref_value.rs -o fix_ref_value
$ ./fix_ref_value
5

The output is 5, read through the reference by the formatting machinery. The found type, &{integer}, is worth pausing on: a reference to a function or a closure can be called, because the call expression dereferences the function operand as required, per the Reference - but a reference to an integer dereferences to an integer, and the integer is what the call is then judged against.

The eleventh failure: an indexing result

A program that calls the result of indexing into a Vec:

Rust
fn main() {
    let v = vec![10, 20];
    v[0]();
}
Terminal
$ rustc --edition 2021 fail_index_result.rs -o fail_index_result
error[E0618]: expected function, found `{integer}`
 --> fail_index_result.rs:3:5
  |
3 |     v[0]();
  |     ^^^^--
  |     |
  |     call expression requires function

error: aborting due to 1 previous error

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

The index expression produces the element, an integer, and the element is the end of the computation. The fix prints it:

Rust
fn main() {
    let v = vec![10, 20];
    println!("{}", v[0]);
}
Terminal
$ rustc --edition 2021 fix_index_value.rs -o fix_index_value
$ ./fix_index_value
10

The output is 10, the first element. Like the eighth family, the failing line reads as a two-step operation - fetch, then run - and like that family it is legal exactly when the fetched thing is callable: a Vec of closures can be indexed and called in one expression, because the element type then implements an Fn trait. With an integer element type, the index is the value and there is no second step.

Five more shapes that fail the same way

The same header, with the same repair - use the value, drop the call - for a char, a float, an array, an Option value, and a unit struct value. Each of these programs fails with exactly one E0618 and no other error:

A char:

Rust
fn main() {
    let c = 'a';
    c();
}

A float:

Rust
fn main() {
    let x = 1.5;
    x();
}

An array:

Rust
fn main() {
    let a = [1, 2];
    a();
}

An Option value - Some(5) is the constructor call, already made; the binding o is the finished value:

Rust
fn main() {
    let o = Some(5);
    o();
}

A unit struct value - Unit is the value itself, like the unit variant in the fifth family:

Rust
struct Unit;
fn main() {
    let u = Unit;
    u();
}

When the call is real: the callable neighbors

The repairs above delete calls. These five programs keep theirs, because what stands before the parentheses is genuinely callable - and each is the neighbor of a family above.

A closure is callable, because it implements the Fn traits the Reference names. This is the value the eighth family's program would have needed get to return:

Rust
fn main() {
    let f = || 42;
    println!("{}", f());
}
Terminal
$ rustc --edition 2021 fix_closure_call.rs -o fix_closure_call
$ ./fix_closure_call
42

The output is 42. A variable holding a closure is called exactly like a function - which is also why calling a variable is not always wrong, only wrong when the variable's type has no call behind it.

A function pointer is callable. The function pointer documentation describes function pointers as pointing to code, not data, and callable just like functions; here a function is stored in a fn pointer binding and called through it:

Rust
fn answer() -> i32 {
    42
}
fn main() {
    let f: fn() -> i32 = answer;
    println!("{}", f());
}
Terminal
$ rustc --edition 2021 fix_fn_pointer.rs -o fix_fn_pointer
$ ./fix_fn_pointer
42

The output is 42. Storing a function in a variable does not make the variable uncallable - it makes it a function pointer, which is a callable type. The families above failed because their variables held data.

A function that returns a closure can be called twice in a row - the legal twin of the eighth family:

Rust
fn make() -> impl Fn() -> i32 {
    || 42
}
fn main() {
    println!("{}", make()());
}
Terminal
$ rustc --edition 2021 fix_fn_returning_closure.rs -o fix_fn_returning_closure
$ ./fix_fn_returning_closure
42

The output is 42. make() returns an impl Fn() -> i32, and the second pair of parentheses calls that return value. Placed beside the eighth family, the two programs differ in one word of the function signature - the return type - and that word is the entire difference between E0618 and a working double call.

A tuple struct constructor is a call. Building a Pair uses parentheses, because the name denotes the constructor:

Rust
struct Pair(i32, i32);
fn main() {
    let p = Pair(1, 2);
    println!("{} {}", p.0, p.1);
}
Terminal
$ rustc --edition 2021 fix_tuple_struct_ctor.rs -o fix_tuple_struct_ctor
$ ./fix_tuple_struct_ctor
1 2

The output is 1 2. This is the constructor the third and ninth families were reaching past: the call belongs at construction time, on the type's name - after it, the instance is a value.

A tuple enum variant constructor is a call, for the same reason - the direct contrast with the fifth family's unit variant:

Rust
#[derive(Debug)]
enum E {
    V(i32),
}
fn main() {
    let e = E::V(3);
    println!("{:?}", e);
}
Terminal
$ rustc --edition 2021 fix_tuple_variant_ctor.rs -o fix_tuple_variant_ctor
warning: field `0` is never read
 --> fix_tuple_variant_ctor.rs:3:7
  |
3 |     V(i32),
  |     - ^^^
  |     |
  |     field in this variant
  |
  = note: `E` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
  |
3 -     V(i32),
3 +     V(()),
  |

warning: 1 warning emitted

$ ./fix_tuple_variant_ctor
V(3)

The output is V(3). The compiler warns that the variant's field is never read - the program prints the value through its derived Debug rather than reading the field - and the warning is left in, because it is part of what this compiler says about this program. The variant takes parentheses because it has a field for them to carry; the unit variant in the fifth family has none.

The fixes in reach order

  • Read the found type in the header. It names what the callee expression actually is, and in most programs that type is the value the code wanted all along - delete the parentheses and use it.
  • The callee is a local with the same name as a function: rename the local (or the function). The diagnostic's shadowing note confirms this is the shape before you change anything.
  • The callee is a unit variant or a unit struct: write it without parentheses. It is already the complete value.
  • A method was intended: name it. s.len(), v.len(), s.get() - the object before the dot, the method's name after it. Bare call parentheses after an object select no operation.
  • A field was intended: drop the parentheses and read the field, s.f, p.x. Field access and calls are different syntax for different things.
  • The expression is the result of an earlier call or an index: that step already finished the computation. Check the producing function's return type - if it is a plain value, use it; only an Fn-implementing return value takes a second call.
  • A call really is intended and the value is data: the design, not the syntax, is off. Store a closure or a function pointer in the binding instead, so the type carries the call with it.
  • The header is not E0618: a "no method named" header is E0599 and a wrong-argument-count header is E0057 or E0061 - both in the traps, both fixed differently.

Traps

  • A struct field written with call parentheses is not E0618. The parser reads s.f() as a method call, so a data field called this way fails with E0599, "no method named f":
Rust
struct S {
    f: i32,
}
fn main() {
    let s = S { f: 7 };
    s.f();
}
Terminal
$ rustc --edition 2021 fail_field.rs -o fail_field
error[E0599]: no method named `f` found for struct `S` in the current scope
 --> fail_field.rs:6:7
  |
1 | struct S {
  | -------- method `f` not found for this struct
...
6 |     s.f();
  |       ^-- help: remove the arguments
  |       |
  |       field, not a method

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0599`.
Trap
The diagnostic even supplies the reading: "field, not a method", with a help to remove the arguments - leaving s.f, the field read that the fix in the third family uses. When the header names a method instead of a function, the parentheses after a dot are the problem, not the value before them. - A function pointer stored in a struct field cannot be called with plain method syntax either - s.f() is still read as a method call and fails with the same E0599, even though the field genuinely holds something callable:
Rust
struct S {
    f: fn() -> i32,
}
fn answer() -> i32 {
    42
}
fn main() {
    let s = S { f: answer };
    println!("{}", s.f());
}
Terminal
$ rustc --edition 2021 trap_fn_field_direct.rs -o trap_fn_field_direct
error[E0599]: no method named `f` found for struct `S` in the current scope
 --> trap_fn_field_direct.rs:9:22
  |
1 | struct S {
  | -------- method `f` not found for this struct
...
9 |     println!("{}", s.f());
  |                      ^ field, not a method
  |
help: to call the function pointer stored in `f`, surround the field access with parentheses
  |
9 |     println!("{}", (s.f)());
  |                    +   +

error: aborting due to 1 previous error

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

The help prescribes the repair: surround the field access with parentheses, so the expression is a value being called rather than a method being looked up:

Rust
struct S {
    f: fn() -> i32,
}
fn answer() -> i32 {
    42
}
fn main() {
    let s = S { f: answer };
    println!("{}", (s.f)());
}
Terminal
$ rustc --edition 2021 trap_fn_field_parens.rs -o trap_fn_field_parens
$ ./trap_fn_field_parens
42

The output is 42. The extra parentheses are the whole difference between the two programs - method-call syntax binds tighter than the call, and breaking the field access out of it is what lets the function pointer be the callee. - A real method call is the third leg of that triangle, and it compiles as written - a method defined in an impl block, called by name:

Rust
struct S {
    f: i32,
}
impl S {
    fn get(&self) -> i32 {
        self.f
    }
}
fn main() {
    let s = S { f: 7 };
    println!("{}", s.get());
}
Terminal
$ rustc --edition 2021 fix_method_call.rs -o fix_method_call
$ ./fix_method_call
7

The output is 7. Field, function pointer field, and method look alike at the call site - s.f, (s.f)(), s.get() - and each has exactly one correct form. E0618 never appears among them, because the dot routes the expression to field and method resolution before call checking. - Shadowing a function with a closure compiles - and silently changes what the call runs:

Rust
fn foo() -> i32 {
    42
}
fn main() {
    let foo = || 7;
    println!("{}", foo());
}
Terminal
$ rustc --edition 2021 trap_shadow_closure.rs -o trap_shadow_closure
warning: function `foo` is never used
 --> trap_shadow_closure.rs:1:4
  |
1 | fn foo() -> i32 {
  |    ^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: 1 warning emitted

$ ./trap_shadow_closure
7

The output is 7, the closure's value, not the function's 42 - and the compiler warns that the function is never used, which is the only sign the substitution happened. Placed beside the fourth family: shadowing with data is a loud E0618, shadowing with a callable is a silent behavior change. Renaming the local is the fix for both. - A callable called with the wrong number of arguments is a different error family. A closure taking one argument, called with none, is E0057:

Rust
fn main() {
    let f = |x: i32| x + 1;
    println!("{}", f());
}
Terminal
$ rustc --edition 2021 trap_closure_wrong_args.rs -o trap_closure_wrong_args
error[E0057]: this function takes 1 argument but 0 arguments were supplied
 --> trap_closure_wrong_args.rs:3:20
  |
3 |     println!("{}", f());
  |                    ^-- argument #1 of type `i32` is missing
  |
note: closure defined here
 --> trap_closure_wrong_args.rs:2:13
  |
2 |     let f = |x: i32| x + 1;
  |             ^^^^^^^^
help: provide the argument
  |
3 |     println!("{}", f(/* i32 */));
  |                      +++++++++

error: aborting due to 1 previous error

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

And a function taking two arguments, called with one, is E0061:

Rust
fn add(a: i32, b: i32) -> i32 {
    a + b
}
fn main() {
    println!("{}", add(1));
}
Terminal
$ rustc --edition 2021 trap_fn_wrong_args.rs -o trap_fn_wrong_args
error[E0061]: this function takes 2 arguments but 1 argument was supplied
 --> trap_fn_wrong_args.rs:5:20
  |
5 |     println!("{}", add(1));
  |                    ^^^--- argument #2 of type `i32` is missing
  |
note: function defined here
 --> trap_fn_wrong_args.rs:1:4
  |
1 | fn add(a: i32, b: i32) -> i32 {
  |    ^^^         ------
help: provide the argument
  |
5 |     println!("{}", add(1, /* i32 */));
  |                         +++++++++++

error: aborting due to 1 previous error

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

In both, the callee passed the test E0618 applies - it is a function - and failed a later one, the argument count. If the diagnostic counts arguments, the callee was never the problem.

Checklist

  • The found type in the header read first, and the repair chosen from what that type is - value, shadowed name, variant, or result - before any code changed.
  • Finished values used as values: no call parentheses left after an integer, a string, a collection, a tuple, a reference, an index, or a function's return value.
  • A shadowed function name freed by renaming the local binding, with the shadowing note in the diagnostic confirming the shape.
  • Unit variants and unit structs written without parentheses; tuple variants and tuple structs constructed with them.
  • Intended methods called by name after a dot, and intended fields read without parentheses.
  • A function pointer held in a struct field called as (s.f)(), with the field access parenthesized out of method position.
  • A binding that must stay callable holding a closure or a function pointer, so its type carries the call.
  • The header checked before the repair: E0618 for an uncallable callee, E0599 for a method-shaped call, E0057 or E0061 for an argument count.
  • The fixed program run, and its output checked against what the program was meant to print.

Sources

  • Rust, Error codes index: E0618 — for the definition of the error as an attempt to call something which is not a function nor a method, for its two examples, a unit enum variant written with parentheses and an i32 variable called as x(), and for the statement that only functions and methods can be called using ().
  • The Rust Reference, Call expressions — for a call expression as a function operand followed by argument operands, for non-function types being called through the Fn, FnMut, and FnOnce traits - and async closures through AsyncFn, AsyncFnMut, and AsyncFnOnce - according to how the value is borrowed, and for the function operand being automatically dereferenced as required.
  • Rust, fn primitive type — for function pointers as pointers that point to code, not data, for their being callable just like functions, and for all safe function pointers implementing Fn, FnMut, and FnOnce.

Keep Exploring