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

Discuss unambiguous function call syntax #45

Merged
merged 3 commits into from
May 26, 2017
Merged

Conversation

mrhota
Copy link
Contributor

@mrhota mrhota commented Apr 18, 2017

And shrink the undocumented list

CC #9

And shrink the undocumented list
<T as SizeOf>::size_of()
```

Refer to [RFC 132] for further details, motivations, and subtleties of syntax.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this temporary? RFC 1636 seems to say that RFCs aren't supposed to be stable documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, I want to keep the link to the RFC. I need more explanation before the link, though. As that RFC says, the reference should be good enough for normal users to learn how to use a feature without referring to the RFC. Thanks for pointing that RFC out; I'd forgotten about it!

@mrhota
Copy link
Contributor Author

mrhota commented Apr 18, 2017

Note to self: Needs more and better examples

@mrhota
Copy link
Contributor Author

mrhota commented Apr 19, 2017

r? @steveklabnik

* Auto-`deref` is undesirable; for example, distinguishing between methods on a
smart pointer itself and the pointer's referent.
* Methods which take no arguments and return properties of a type, like
`SizeOf::size_of()`
Copy link
Member

Choose a reason for hiding this comment

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

What is SizeOf?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took the example from the RFC. It became out-of-date, apparently! I'll correct it.

* Auto-`deref` is undesirable; for example, distinguishing between methods on a
smart pointer itself and the pointer's referent
* Methods which take no arguments, like `default()`, and return properties of a
type, like `size_of()`
Copy link
Member

Choose a reason for hiding this comment

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

How could default() result in an ambiguity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fn main() {
    let a = Default::default();
    println!("{:?}", a);
}

You can (must) use a type annotation or UFCS, right?

@frewsxcv
Copy link
Member

This seems alright to me, seems like it could be a little more detailed with some of the specifics of the syntax, but I still feel comfortable landing it in its current state. Any else have thoughts? @steveklabnik @GuillaumeGomez @QuietMisdreavus

@GuillaumeGomez
Copy link
Member

Feel the same: could be more detailed.

@QuietMisdreavus
Copy link
Member

It might be worth mentioning the <SomeType as SomeTrait>::some_function() details in prose as well, instead of just leaving it to code examples? Even if you just add one sentence that includes that one snippet, I like seeing a generalized form somewhere.

@mrhota
Copy link
Contributor Author

mrhota commented May 1, 2017

@GuillaumeGomez @QuietMisdreavus @frewsxcv I'd love to add more examples and detail, but I'm afraid the RFC itself seems somewhat out-of-date (SizeOf???) and a bit lacking in context. Seems like it sort of leaps into the topic midstream...

If y'all have any examples I could include, I'd appreciate it! I'll see what I can come up with tonight.

@QuietMisdreavus
Copy link
Member

QuietMisdreavus commented May 1, 2017

I was just wanting another sentence or two describing the full form, and mentioning that either SomeType or SomeTrait can be inferred most of the time, but that UFCS is there when you need both.

Edit: Unless there's more to UFCS than <SomeType as SomeTrait>::some_function()...?

Function calls may sometimes result in ambiguities about receiver or referent.
See [UFCS](#unambiguous-function-call-syntax) for how to resolve this.

### Unambiguous Function Call Syntax (UFCS)
Copy link
Member

Choose a reason for hiding this comment

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

So, it's been the opinion of the language team for a long time that "UFCS" is a terrible name and shouldn't be used. It's also not exactly a separate feature, it's that the usual way of calling trait methods is sugar for this syntax. As such, I'm not sure the framing of this PR is right, though there is no way for you to have known that, of course. ☹️

I am tempted to merge it as such, and then, we'll end up doing another pass later that cleans this up. This is okay with me, but I don't know how you feel about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh that's helpful. with that in mind, maybe I can have a sub-section here instead of the new section I created? I can describe roughly what you said: "UFCS" confuses the issue, and the RFC didn't add a separate feature. It merely generalized some syntax and turned the then-current syntax into sugar for the fully-qualified function-call syntax. FQFC.

iono @steveklabnik, I'll push some updates, and you can tell me what you think.

Copy link
Member

Choose a reason for hiding this comment

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

that sounds good to me

@mrhota
Copy link
Contributor Author

mrhota commented May 22, 2017

@steveklabnik let me know what you think of the description now

Copy link
Member

@steveklabnik steveklabnik left a comment

Choose a reason for hiding this comment

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

looks good to me; i think a link might be broken though?

@@ -220,6 +220,9 @@ exact `self`-type of the left-hand-side is known, or dynamically dispatching if
the left-hand-side expression is an indirect [trait
object](types.html#trait-objects).

[UFCS](#unambiguous-function-call-syntax) allows method invocation using
Copy link
Member

Choose a reason for hiding this comment

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

this link is still wrong, no?

@mrhota
Copy link
Contributor Author

mrhota commented May 22, 2017 via email

@mrhota
Copy link
Contributor Author

mrhota commented May 25, 2017

@steveklabnik @QuietMisdreavus ok, fixed that last link (and rewrote the sentence around it).

@steveklabnik steveklabnik merged commit aa6515b into rust-lang:master May 26, 2017
@steveklabnik
Copy link
Member

Great, thanks!

@mrhota mrhota mentioned this pull request May 26, 2017
48 tasks
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