Quick answer
The method usually does exist — Rust just can't see it. In order of likelihood:
- The method comes from a trait that isn't in scope — add the
use(most common by far). - You're in a generic function with no trait bound — add
<T: Trait>. - A typo or the method has a different name — the compiler suggests the closest match.
- Wrong receiver — you're calling it on an
Option/Resultinstead of the value inside.
The exact error string
use std::fs::File;
fn main() {
let mut f = File::open("data.json").unwrap();
let mut s = String::new();
f.read_to_string(&mut s).unwrap();
}
// error[E0599]: no method named `read_to_string` found for struct `File` in the current scope
// --> src/main.rs:6:7
// |
// 6 | f.read_to_string(&mut s).unwrap();
// | ^^^^^^^^^^^^^^ method not found in `File`
// |
// = help: items from traits can only be used if the trait is in scope
// help: trait `Read` which provides `read_to_string` is implemented but not in scope
// |
// 1 + use std::io::Read;
// |
Read past the first line. method not found in File is technically accurate but misleading — File absolutely does have read_to_string. The line that actually matters is the help: note near the bottom: items from traits can only be used if the trait is in scope. Modern rustc even prints the exact use statement to add. Whenever you see that note, the fix is a one-line import and nothing more.
Fix 1: bring the trait into scope
Rust deliberately only considers trait methods when the trait is imported. Adding the use makes the method resolvable:
use std::fs::File;
use std::io::Read; // ✅ now File::read_to_string resolves
fn main() {
let mut f = File::open("data.json").unwrap();
let mut s = String::new();
f.read_to_string(&mut s).unwrap();
}
This is not the compiler being pedantic. Two different traits can define a method with the same name, and both can be implemented for the same type. If trait methods resolved without an import, adding a dependency could silently change which method your code calls. Requiring the trait in scope makes resolution explicit and stable.
The traits that most often trip people up:
| Missing import | Methods it unlocks |
|---|---|
use std::io::Read; | read_to_string, read_to_end, read_exact |
use std::io::Write; | write_all, write_fmt, flush |
use std::io::BufRead; | lines(), read_line |
use std::str::FromStr; | T::from_str(s) (not .parse() — see note) |
use std::fmt::Write; | write! into a String (collides with io::Write — see note) |
use itertools::Itertools; | unique(), chunks(), join() and friends |
use rand::Rng; | random(), random_range() (renamed from gen()/gen_range() in rand 0.9) |
Two rows need a caveat. .parse::<T>() is an inherent method on str and needs no import at all — it calls FromStr::from_str internally for you; the FromStr import only matters if you write T::from_str(s) directly. And std::fmt::Write and std::io::Write both define a write_fmt-shaped method the compiler can resolve to either one — importing both in the same module is a genuine collision, not a clean drop-in fix, and needs an alias such as use std::fmt::Write as FmtWrite; to disambiguate.
Many crates ship a prelude module that imports their common traits in one line — use anyhow::Context;, use rayon::prelude::*;, use diesel::prelude::*;. If a crate's docs mention a prelude, importing it usually resolves a whole family of E0599s at once.
None of this is limited to the standard library or third-party crates — it applies just as much to a trait you wrote in another module:
trait Printable {
fn print(&self);
}
struct User;
impl Printable for User {
fn print(&self) {
println!("User");
}
}
fn main() {
let user = User;
user.print();
}
// error[E0599]: no method named `print` found for struct `User` in the current scope
// = help: items from traits can only be used if the trait is in scope
// help: trait `Printable` which provides `print` is implemented but not in scope
// |
// 1 + use crate::Printable;
// |
Same fix, same reasoning: add use crate::Printable; (or wherever the trait actually lives). It's worth internalizing that this is just as likely to hit you on a trait you defined yourself as on one from the standard library.
Fix 2: add the missing trait bound on a generic
Inside a generic function, the compiler knows nothing about T beyond the bounds you declared. With no bounds, T has no methods at all — regardless of what you intend to pass in:
// ❌ T has no bounds, so T has no methods
fn print_all<T>(items: Vec<T>) {
for item in items {
println!("{}", item.to_string());
}
}
// error[E0599]: no method named `to_string` found for type parameter `T`
// ✅ declare the capability you rely on
fn print_all<T: ToString>(items: Vec<T>) {
for item in items {
println!("{}", item.to_string());
}
}
// equivalent, and clearer with several bounds:
fn print_all<T>(items: Vec<T>)
where
T: ToString + Clone,
{ /* ... */ }
This is generics working as designed: the bound is a contract stated up front, so the function body is checked once and every caller is verified against it. It's also where E0599 and E0277 (the trait bound is not satisfied) blur together — a missing bound can surface as either depending on where rustc notices the gap, and adding the bound fixes both.
Fix 3: a typo or a differently-named method
When the compiler can find a similarly-named method it says so, and that suggestion is almost always right:
let v = vec![1, 2, 3];
let n = v.length();
// error[E0599]: no method named `length` found for struct `Vec<i32>`
// = help: there is a method `len` with a similar name
let n = v.len(); // ✅
Rust's naming often differs from other languages in small ways that produce exactly this error — len() not length(), push() not append() for a single element, contains() not includes(), to_string() not toString(). When there's no suggestion at all, check the type's docs: the method may live on a different type in the chain than you assumed.
Fix 4: the wrong receiver — Option, Result, and references
This one is easy to misread because the method genuinely exists — just not on the type you're calling it on. A wrapper has the wrapper's methods, not the inner value's:
let name: Option<String> = Some("Alice".to_string());
let n = name.len();
// error[E0599]: no method named `len` found for enum `Option<String>`
// ✅ operate on the inner value
let n = name.map(|s| s.len()); // Option<usize>
let n = name.as_deref().map(str::len); // avoids moving the String
if let Some(s) = &name {
println!("{}", s.len()); // ✅ s is &String here
}
The same shape appears with Result. The error is really telling you to handle the wrapper first — which is Rust doing its job, since the value might be absent. If you find yourself reaching for .unwrap() to get past it, read called Option::unwrap() on a None value first: the combinator forms above are usually the better ending.
A related receiver issue is mutability — and a heads-up before the example: Rust actually files this specific case as E0596, not E0599. It's a different error code, but the same family of "the receiver doesn't support this call" mistake, and worth knowing here. A method taking &mut self can't be called through an immutable binding:
let v = vec![1, 2, 3];
v.push(4); // ❌ E0596: push takes &mut self, not E0599
let mut v = vec![1, 2, 3];
v.push(4); // ✅
The mental fix is the same either way: check what the method needs from its receiver — self, &self, or &mut self.
How to read the error efficiently
- Look for
items from traits can only be used if the trait is in scope— if present, add the suggesteduseand you're done. - Look for
there is a method <name> with a similar name— if present, it's a typo. - If the receiver is a type parameter (
for type parameter T), it's a missing trait bound. - If the receiver is
Option<...>orResult<...>, you're calling the method on the wrapper. - Otherwise, check the type's documentation — the method may be on a different type in the chain.
Debugging checklist
- ✓ Read the
help:lines, not just the first line — rustc usually names the fix - ✓ “trait is in scope” note? Add the
useit suggests (std::io::Read/Writemost often) - ✓ Crate method missing? Check whether the crate has a
preludeto import - ✓ Error mentions
type parameter T? Add the trait bound or awhereclause - ✓ “similar name” suggestion? It's a typo — take the suggestion
- ✓ Receiver is
Option/Result? Unwrap the inner value withmap/if let - ✓ Method needs
&mut self? Make the bindingmut - ✓ Working through a
Box<dyn Trait>or&dyn Trait? Method resolution goes through the trait's own methods, not the concrete type's — check the trait definition, not the struct behind it - ✓ Still stuck?
cargo doc --openor hover the call in your editor (rust-analyzer) to see the type's real method list
Frequently Asked Questions
What does error[E0599]: no method named X found mean?
Rust could not resolve the method you called on that type. It does not necessarily mean the method doesn't exist — the most common cause is that the method comes from a trait that isn't in scope, so the compiler refuses to consider it. Other causes are a missing trait bound on a generic parameter, a simple typo, or calling the method on the wrong receiver type such as a reference or an Option wrapper.
Why do I need to import a trait to call its method?
Rust only considers trait methods when the trait is in scope. This prevents two traits that define the same method name from silently colliding, and keeps method resolution predictable and explicit. So even though a type implements the trait, you must bring the trait into scope with a use statement — for example use std::io::Read; before calling .read_to_string() on a File.
What does 'items from traits can only be used if the trait is in scope' mean?
It's the compiler telling you it found a method with that name on a trait the type implements, but the trait isn't imported so it can't be used. This note is the single most useful line in the error — it usually comes with a suggested use statement. Adding that import is the whole fix.
Why does E0599 appear inside a generic function?
Inside a generic function, Rust only knows about the capabilities you declared through trait bounds. If T has no bounds, T has no methods at all as far as the compiler is concerned, even if every concrete type you plan to pass has the method. Add the bound — fn show<T: Display>(x: T) — or a where clause, so the method becomes available for every T.
How is E0599 different from E0277?
E0599 means the method could not be found at all for that type. E0277 means a trait bound is not satisfied — the compiler found the right method or operation but the type doesn't implement the required trait. In practice a missing trait bound on a generic can surface as either, depending on where the compiler notices the gap, and the fix is often the same: add the bound or implement the trait.
Why does the method exist but not on my Option or Result?
Because the method belongs to the value inside, not to the wrapper. Option<String> has Option's methods, not String's — calling .len() on it fails with E0599. Unwrap the inner value first with a match, if let, or a combinator such as .map(|s| s.len()), or use .as_deref() to get at the inner type. The same applies to Result.
More Rust & backend errors
Browse the full reference for Rust, Go, and Java errors — exact message, cause, and fix.