Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named and destructable self #922

Closed
wants to merge 4 commits into from
Closed

Named and destructable self #922

wants to merge 4 commits into from

Conversation

hauleth
Copy link

@hauleth hauleth commented Mar 2, 2015

@chris-morgan
Copy link
Member

Destruction and destructuring are two rather different things.


# Summary

Allow destructing assignment for `self` argument.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

destructuring
and all the other places

@kennytm
Copy link
Member

kennytm commented Mar 4, 2015

The "Rendered" is a dead link.

@pnkfelix
Copy link
Member

pnkfelix commented Mar 4, 2015

(fixed link)

@pnkfelix
Copy link
Member

pnkfelix commented Mar 5, 2015

Thank you for posting this.

I actually believe the intention, during the UFCS design, was to add this feature (or something very much like it). In particular, you can today already write:

struct Foo(u32, String);

impl Foo {
    fn bar(x: Self) -> String {
        x.1
    }
}

(note however, that one is currently forced to call the above via the syntax Foo::bar(..); the expression f1.bar() for f1: Foo does not yet work; see the comment thread attached to #395 for a little more discussion on this point.)


Anyway, we do already have a start to what you describe. Of course, in addition to the method call issue noted above, it also does not yet allow destructuring. (But I suspect this was an oversight, not a concious design choice.)

@nikomatsakis can you comment on whether the UFCS RFC needs an amendment to include destructuring Self bindings in addition to the current x: Self binding form?

@pnkfelix pnkfelix self-assigned this Mar 5, 2015
@pnkfelix
Copy link
Member

pnkfelix commented Apr 9, 2015

reassigning to @nikomatsakis

@pnkfelix pnkfelix assigned nikomatsakis and unassigned pnkfelix Apr 9, 2015
@nikomatsakis
Copy link
Contributor

Indeed, the already accepted RFC 48 permitted this sort of syntax. That was not implemented. I have some concerns that we may not be able to implement it backwards compatibly -- in particular, we currently use the self keyword to designate methods that should be considered for method dispatch, and growing that set can create ambiguities. Now that we are moving towards 1.0 we'll have to see what is possible and desirable in the future. Nonetheless, I'm going to close this RFC since it is already the official plan, and the limiting factor is more backwards compatibility and implementation time and effort. Thanks very much for the suggestion!

@hauleth hauleth deleted the self-param-as-sugar branch September 17, 2015 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants