Skip to content
TE104 · Type · error

No such method

The receiver type does not have a method with this name. Check spelling, imports, and trait visibility.

Why this fires

The receiver does not have a method with the given name. Concrete causes:

  • A typo (.lenght() instead of .length()).
  • The method exists on a different type than the receiver is.
  • The method comes from a trait that isn't in scope.
  • Visibility — the method is declared but not pub.
let s = "hello"
let n = s.lenght()
//      ^^^^^^^^ error: no method `lenght` on `str` — did you mean `length`?

Fix it

1. Fix the spelling

Trust the "did you mean?" suggestion when it appears.

2. Bring the trait into scope

For methods provided by a trait:

use std::iter::Iterator   // brings `.map`, `.filter`, etc. into scope

3. Check the receiver's actual type

The "I'm sure the method exists" case usually means the receiver is a different type than you expect. Add an explicit annotation or hover the value in the editor to confirm:

let parsed: int = parse(input)   // make the type explicit at the call site
let s = parsed.to_str()

4. Mark the method pub

If you declared the method in an impl block in another module, make sure it's pub.

See also

  • TE100 — undefined variable (different lookup mechanism).
  • /docs/stdlib — built-in methods on str, int, float, etc.
enespt-br