Skip to content

unified function call syntax #4

New issue

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

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

Already on GitHub? # to your account

Closed
wants to merge 1 commit into from
Closed

unified function call syntax #4

wants to merge 1 commit into from

Conversation

nrc
Copy link
Member

@nrc nrc commented Mar 12, 2014

No description provided.

```
fn f<G: Graph>(n1: (G:Graph)::Node, n2: G::Node) { // n1 and n2 have the same type
...
let x = G::Node::magic_number; // associated value
Copy link
Member

Choose a reason for hiding this comment

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

The full syntax for this is written as (G: Graph)::Node::magic_number, right?

I'm still mildly concerned about this from a grammar perspective, especially if we ever use : for type ascription on expressions (because then in (x: y..., x can legitimately be either a type or an expression).

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there is any particular ambiguity so long as we restrict the set of type expressions to paths. Though this is perhaps an unfortunate limitation.

Copy link
Member

Choose a reason for hiding this comment

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

Even with just paths, it means that something like (Foo<T>: Graph) can't work (unless we use Foo::<T> there too).

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, you would write Foo::<T> if this appears in an expression context.

@alexcrichton
Copy link
Member

As a side note, could you format this to a line width of 80 characters?

@ben0x539
Copy link

Does this proposal exclude int::size_of()? ~[T]::size_of()? type MyVec = ~[T]; MyVec::size_of()?

@nrc
Copy link
Member Author

nrc commented Mar 18, 2014

@ben0x539 All those should work, the components of a path should be allowed to be types, not just trait or struct names

@nikomatsakis
Copy link
Contributor

I thought it disallowed things like ~[T]::size_of() -- you'd need a type alias. I don't know how we can parse it otherwise.

@brendanzab
Copy link
Member

Does this cover the idea that:

trait A {
    fn a(&self) -> Self;
}

Is just sugar for:

trait A {
    fn a(self: &Self) -> Self;
}

?

@nikomatsakis
Copy link
Contributor

@bjz I think that comes out of my (not yet published) RFC on traits. I need to get to work on finishing that.

@SiegeLord
Copy link

From reading the proposal, it wasn't clear to me how this case would be handled:

trait T
{
    fn method(&self) {}
}

struct A;

impl A
{
    fn method(&self) {}
}

impl T for A {}

fn main()
{
    let a = A;
    (A: T)::method(a); // easy to call the trait's method
    A::method(a); // but how to call the inherent method?
}

@nrc
Copy link
Member Author

nrc commented Apr 7, 2014

@SiegeLord This is a little bit orthogonal, since it is about calling overridden vs overriding methods rather than specifying a method in one trait from a set of traits.

a.method would call the method defined in the struct (currently) and would continue to do so. T::method(a) would call the method in the trait (I think currently too). No need for the more verbose form here.

@nrc
Copy link
Member Author

nrc commented Jun 22, 2014

Closed in favour of #132

@nrc nrc closed this Jun 22, 2014
alexcrichton referenced this pull request in alexcrichton/rfcs Feb 2, 2015
wycats added a commit that referenced this pull request Nov 16, 2015
withoutboats referenced this pull request in withoutboats/rfcs Jan 15, 2017
withoutboats pushed a commit that referenced this pull request Apr 24, 2017
Explicitly point out alternatives to `trait Alias = where PREDICATES;`
Centril added a commit that referenced this pull request Jul 24, 2018
Manishearth referenced this pull request in Manishearth/rfcs Mar 19, 2019
Document more Community Team goals
sophiajt pushed a commit to sophiajt/rfcs that referenced this pull request Mar 29, 2021
epage pushed a commit to epage/rfcs that referenced this pull request Mar 28, 2022
Expand on the guide-level explanation
Mark-Simulacrum pushed a commit that referenced this pull request Jun 15, 2023
Add RFC summary translations
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants