First of all, I am aware of the Github issue Implement UFCS (Tracking RFC 132) and why the name self
cannot be made insignificant. A function is a method if and only if its first argument is called self
- I agree with this and I do not propose to change this.
However, why won't this work?
struct S {
i: i32,
f: f64,
}
impl S {
fn fun(self @ Self {i, f} : Self) {
println!("{i}, {f}");
}
}
fn main() {
let s = S {i: 5, f: 5.5};
s.fun();
}
I believe the above code should compile and work as expected. Yet it does not even compile.
- The first argument of
fun
is calledself
, thereforefun
should be a valid method. - This is valid destructuring syntax. Replace
self
with any other name andfun
will compile & work, though it will not be a method.