# \`self\` destruction assignment

**URL:** <https://internals.rust-lang.org/t/self-destruction-assignment/1668>\
**Category:** ideas (deprecated)\
**Created:** [March 1, 2015, 5:47pm UTC](https://internals.rust-lang.org/t/self-destruction-assignment/1668 "2015-03-01T17:47:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hauleth](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/hauleth/32/1322_2.png) [@hauleth](https://internals.rust-lang.org/u/hauleth)\
**Post date:** [March 1, 2015, 5:47pm UTC](https://internals.rust-lang.org/t/self-destruction-assignment/1668/1 "2015-03-01T17:47:48Z")

</div>

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

```rust
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)?

---

<div class="post-metadata">

**Author:** ![sinistersnare](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/sinistersnare/32/18_2.png) [@sinistersnare](https://internals.rust-lang.org/u/sinistersnare)\
**Post date:** [March 1, 2015, 8:44pm UTC](https://internals.rust-lang.org/t/self-destruction-assignment/1668/2 "2015-03-01T20:44:29Z")

</div>

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

```rust
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.

---

<div class="post-metadata">

**Author:** ![hauleth](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/hauleth/32/1322_2.png) [@hauleth](https://internals.rust-lang.org/u/hauleth)\
**Post date:** [March 1, 2015, 8:51pm UTC](https://internals.rust-lang.org/t/self-destruction-assignment/1668/3 "2015-03-01T20:51:56Z")

</div>

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

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

```

and

```rust
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`.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:10am UTC](https://internals.rust-lang.org/t/self-destruction-assignment/1668/4 "2019-03-25T08:10:17Z")

</div>

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