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

UFCS RFC needs to be clearer about method call syntax #395

Open
pnkfelix opened this issue Oct 14, 2014 · 7 comments
Open

UFCS RFC needs to be clearer about method call syntax #395

pnkfelix opened this issue Oct 14, 2014 · 7 comments
Assignees
Labels
A-resolve Proposals relating to name resolution. A-syntax Syntax related proposals & ideas T-lang Relevant to the language team, which will review and decide on the RFC.

Comments

@pnkfelix
Copy link
Member

RFC PR #132 (UFCS) had many descriptions of various paths, but completely omitted concrete examples of an actual method call (with the receiver expression and the arguments) written via the proposed notation.

In particular, assuming a trait ToStr { fn to_str(&self) -> String } and type S that implements ToStr and also has its own impl S { fn to_str(&self, max: uint) -> String } are we expecting to be able to write:

  • fn f(s: &S) -> String { s.ToStr::to_str() }, or
  • fn f(s: &S) -> String { ToStr::to_str(s) }, or
  • both?

and likewise:

  • fn g(s: &S) -> String { s.<S>::to_str(10) }, or
  • fn g(s: &S) -> String { <S>::to_str(s, 10) }, or
  • both?

(Perhaps the answer is implied by some other document that specifies whether method call expressions use a full path for the method name, or just an identifier and optional generics args list ::<T, U, ...>. Nonetheless this detail is important enough to go into the document itself.)

@pnkfelix
Copy link
Member Author

cc @nikomatsakis

@nrc
Copy link
Member

nrc commented Oct 15, 2014

At least the second option for both.

I think the first form should also be allowed since at worse it will be redundant and in some cases could restrict the traits examined in trait matching, whilst still doing dynamic dispatch.

@aturon
Copy link
Member

aturon commented Oct 15, 2014

cc me

@pnkfelix
Copy link
Member Author

Another argument for supporting s.ToStr::to_str() and s.<S>::to_str(10) : the other form lacks autoref/autoderef for the receiver s

@nikomatsakis
Copy link
Contributor

The UFCS RFC did not propose any way to use method-call syntax in this fashion. This would be a distinct RFC, I believe.

@petrochenkov petrochenkov added the T-lang Relevant to the language team, which will review and decide on the RFC. label Jan 19, 2018
@Havvy
Copy link
Contributor

Havvy commented Oct 17, 2018

Is this still valid?

@pnkfelix
Copy link
Member Author

I’ll review

@pnkfelix pnkfelix self-assigned this Oct 17, 2018
@Centril Centril added A-syntax Syntax related proposals & ideas A-resolve Proposals relating to name resolution. labels Nov 27, 2018
wycats pushed a commit to wycats/rust-rfcs that referenced this issue Mar 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-resolve Proposals relating to name resolution. A-syntax Syntax related proposals & ideas T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

7 participants