E0041
Error
self outside a method
Errorself names the object a method was called on, so it is only available inside a method.
Why
A function that is not a method has no object to refer to. A field is reached through the object, so such a function takes the object as a parameter, or becomes a method.
Broken
class Counter {
n: i64
}
fn show() {
print(self.n)
}
fn main() {
show()
}
What sisu says
error[E0041]: `self` is only available in a method --> E0041.sisu:6:11 | 6 | print(self.n) | ^^^^ sisu: 1 error sisu: for more on a code, run `sisu explain <code>`: E0041
Fixed
class Counter {
n: i64
fn show(self) {
print(self.n)
}
}
fn main() {
Counter(n: 1).show()
}
Sisu