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

[r+] Implement fully qualified UFCS expressions. #21077

Merged
merged 3 commits into from
Jan 15, 2015

Conversation

eddyb
Copy link
Member

@eddyb eddyb commented Jan 13, 2015

Working towards #16293, this adds support for <T as Trait>::method in expressions.

@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@eddyb
Copy link
Member Author

eddyb commented Jan 13, 2015

@nikomatsakis I almost want to separate ast::Path into a Vec<ast::PathSegment> and a terminal ast::PathSegment - most of the code out there that touches paths uses .last().unwrap() and having to produce ast::Path from ast::QPath isn't really optimal (but I chose it instead of duplicating lots of resolve and typeck logic).

@nikomatsakis
Copy link
Contributor

r+. This looks great. The one thing I'd like to see is a more diverse array of tests, for example:

  1. A run-pass test where the trait has a type parameter (<Foo as Trait<X>>::item()).
  2. A run-pass test where the trait has a region parameter.
  3. A compile-fail test where the self type that is provided doesn't match what the user provides (<i32 as Trait>::method(3_u32)).

@nikomatsakis
Copy link
Contributor

@eddyb regarding Path, I personally would like to refactor it into something recursive, rather than the current vector of path segments. I don't think the vector is particularly helpful. Having something recursive (a cons list, basically) would also make trivial to extract the last name, as you say.

@nikomatsakis nikomatsakis changed the title Implement fully qualified UFCS expressions. [r+] Implement fully qualified UFCS expressions. Jan 14, 2015
@huonw
Copy link
Member

huonw commented Jan 14, 2015

Is it worth having some tests with default type parameters (in traits and types)?

Also, does using _ work? e.g. <Option<_> as PartialEq>::eq(&Some(1u8), &None).

@eddyb
Copy link
Member Author

eddyb commented Jan 14, 2015

@huonw yes it does - also, the implementation results in <_ as Foo>::bar being identical to Foo::bar, type-wise.

@eddyb
Copy link
Member Author

eddyb commented Jan 14, 2015

I don't think I handle <T as PolyTrait>::foo correctly, given trait PolyTrait<T> - that is, it works, just like PolyTrait::foo does, where the type param is optional.
I guess I'll just use instantiate_trait_ref, which will require that all type params are present, and add a compile-fail test for this case.

@nikomatsakis
Copy link
Contributor

as we said on IRC, I actually expected <T as PolyTrait>::foo to make fresh type variables and work. But I could probably go either way on this, given that we have _.

bors added a commit that referenced this pull request Jan 15, 2015
[r+] Implement fully qualified UFCS expressions.

Reviewed-by: nikomatsakis
bors added a commit that referenced this pull request Jan 15, 2015
Working towards #16293, this adds support for `<T as Trait>::method` in expressions.
@bors bors merged commit 85ba817 into rust-lang:master Jan 15, 2015
@eddyb eddyb deleted the expr-qpath branch January 16, 2015 03:02
SSheldon added a commit to SSheldon/rust-objc that referenced this pull request Feb 27, 2015
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.

5 participants