`self` destruction assignment

Currently we can destruct-while-calling any argument except self. I.e.

struct Foo(i32, i32);

fn foo(Foo(a, b): Foo) {}

foo(Foo(1, 2))

impl Foo {
  // fn foo(Foo(a, b)) {} won't work (at least if it is trait implementation
  // fn foo(Foo(a, b): self) won't work either (1)
  // fn foo(Foo(a, b): Self) either (2)
}

Is there any way to achieve this without additional let Foo(a, b) = self line? If no maybe it is worth to consider allowing syntax (1) or (2)?

Now that Self is allowed in impls, it may be a cool idea:

struct Foo(i32, i64);
impl Foo {
    fn baz(Foo(a, b): Self) { ... }
}

But because other arguments can have the type of Self, there might be problems in parsing? Idk Rust internals so who knows.

IMHO any method that takes Self as first argument should be callable as method, so these will be equivalent:

impl Foo {
  pub fn foo(self) {}
}

and

impl Foo {
  pub fn foo(bar: Self) {}
}

The same goes for references. self would be simply sugar for self: Self and &self for self: &Self.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.