Email me

Rust errors / Types and traits

Rust compiler error · checked with rustc 1.99.0

Rust error E0599: no method named X found in the current scope

What it meansThe method does not exist on that type, or it comes from a trait that is not imported, or its trait bounds are not met.

What rustc prints

error[E0599]: no method named `chocolate` found for struct `Mouth` in the current scope
 --> main.rs:6:3
  |
3 | struct Mouth;
  | ------------ method `chocolate` not found for this struct
...
6 | x.chocolate(); // error: no method named `chocolate` found for type `Mouth`
  |   ^^^^^^^^^ method not found in `Mouth`

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

  • Trait methods (like read_to_string from std::io::Read, or .write_all) need the trait in scope.
  • Calling a method on Option<T> or Result<T, E> that belongs to T; unwrap or match first.
  • Calling .iter() methods on something that is not an iterator, or a method from a newer crate version than the one you have.
  • A derive is missing, so a method that needs Clone or Ord is unavailable.

How to fix it

1. Import the trait

The compiler often names it in a help line.

use std::io::Read;
let mut s = String::new();
file.read_to_string(&mut s)?;

2. Unwrap the Option or Result first

The method is on the inner type.

let len = maybe_name.as_ref().map(|n| n.len()).unwrap_or(0);

Other wordings of this error

no method named X found in the current scope, no method named found, method not found in, no function or associated item named, items from traits can only be used if the trait is in scope, the method exists but the following trait bounds were not satisfied

E0599Types and traits
Activein rustc 1.99.0
8related errors linked below

The compiler team's explanation

This error occurs when a method is used on a type which doesn't implement it:

Erroneous code example:

struct Mouth;

let x = Mouth;
x.chocolate(); // error: no method named `chocolate` found for type `Mouth`
               //        in the current scope

In this case, you need to implement the chocolate method to fix the error:

struct Mouth;

impl Mouth {
    fn chocolate(&self) { // We implement the `chocolate` method here.
        println!("Hmmm! I love chocolate!");
    }
}

let x = Mouth;
x.chocolate(); // ok!

From rustc --explain E0599 (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 nextE0308: mismatched typesA 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