Skip to content
Playground(another site)

bynk.parse.self_outside_method

Error self is the first parameter of a free function; only a method declaration, fn Type.method(self, …), has a receiver.

self is the receiver of a method, and only the first parameter of a method declaration, written fn Type.method(self, …), may be named self. A free function has no receiver. Either name the type the function belongs to, making it a method, or drop self and take the value as an ordinary parameter.

Example

fn total(self) -> Int { // ✗ a free function has no `self`
self.total
}
fn Order.total(self) -> Int { // ✓ a method of `Order`
self.total
}

In the Book

See also

  • The grammar rule it governs: self_expr.
  • Every code in its category, Parser, on the diagnostic index.
  • bynk explain bynk.parse.self_outside_method shows the same from the installed toolchain, without a network.