Skip to content

support partial type hints #9508

Closed
Closed
@thestinger

Description

@thestinger
Contributor

I want to be able to write this:

let xs: HashSet<_> = iter.collect();

rather than:

let xs: HashSet<SomeLongType<A, B>> = iter.collect();

I really don't like the idea of having special cases like to_owned_vec in std::iter to work around this issue:

fn to_owned_vec(&mut self) -> ~[A] {
    self.collect()
}

It doesn't fix the pain in the general case, and encourages using a specific container we special case rather than the right container for the use case. I think this problem will come up frequently with generic code, and the _ syntax would feel right at home with the usage elsewhere.

Activity

nikomatsakis

nikomatsakis commented on Sep 30, 2013

@nikomatsakis
Contributor

This seems useful and like it would not be too hard to implement -- we just have to be sure to disallow such hints in places where they are not legal. Would we permit you to omit the list of type parameters altogether? (i.e., HashSet or do we require HashSet<_>?) Should we extend this to lifetime names Foo<'_>? The latter looks really ugly to me :)

thestinger

thestinger commented on Oct 26, 2013

@thestinger
ContributorAuthor

@nikomatsakis: I think it would probably make sense to start with the minimal feature (individual parameters) and enhance it if compelling use cases come up.

nikomatsakis

nikomatsakis commented on Oct 28, 2013

@nikomatsakis
Contributor

I have had some thoughts in the meantime as part of my work on #4846 and have a larger proposal to make that would encompass this issue.

nikomatsakis

nikomatsakis commented on Oct 29, 2013

@nikomatsakis
Contributor
metajack

metajack commented on Dec 22, 2013

@metajack
Contributor

+1. I recent ran into some code in Servo that would benefit from this.

Kimundi

Kimundi commented on Mar 14, 2014

@Kimundi
Member

This is supported now.

alexcrichton

alexcrichton commented on Mar 14, 2014

@alexcrichton
Member

Closed by #12764, thanks @Kimundi!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @metajack@alexcrichton@nikomatsakis@thestinger@Kimundi

        Issue actions

          support partial type hints · Issue #9508 · rust-lang/rust