E0020
Error
self that is not the first parameter
Errorself is only the first parameter of a method. It cannot follow another parameter, repeat, or appear in a function outside a class.
Why
A method call object.method(x) passes the object first, so self must come first in the declaration too.
Broken
class Counter {
mut n: i64
fn add(by: i64, self) {
self.n += by
}
}
fn main() {
let c = Counter(n: 0)
c.add(2)
print(c.n)
}
What sisu says
error[E0020]: `self` is only the first parameter of a method --> E0020.sisu:4:21 | 4 | fn add(by: i64, self) { | ^^^^ sisu: 1 error sisu: for more on a code, run `sisu explain <code>`: E0020
Fixed
class Counter {
mut n: i64
fn add(self, by: i64) {
self.n += by
}
}
fn main() {
let c = Counter(n: 0)
c.add(2)
print(c.n)
}
Sisu