Skip to content

Why is the ... as ... part needed to evaluate property functions? #216

Closed

Description

@mcandre

Curious, why do I need to remind the compiler that my fn (seed : usize, password : String) -> bool { ... } is a fn(usize, String) -> bool with the as token when I pass this function to quickcheck::quickcheck()?

As a workaround, I am declaring my properties as lambdas variables, explicitly typed to their signatures. But I would prefer not to have to do this.

Activity

  1. BurntSushi commented on Oct 28, 2018

    @BurntSushi
    Owner

    Nobody would prefer to do this. I think this requirement was introduced here by making each fn item have its own distinct type: rust-lang/rust#19891

    There is already an issue tracking this problem for quickcheck, and in particular, we would like to be ablw to use closures for property functions: #56

    The quickcheck macro is meant to alleviate this annoyance in some cases.

  2. DestyNova commented on Feb 17, 2020

    @DestyNova

    Hi @BurntSushi -- I'm just a beginner with Rust but I'm struggling to understand what the benefit of that "unique type per fn item" PR was. We can see the downside of it is lots of extra as fn(...) -> ... annotations in heavily functional code, but there must have been some good reason to do it that outweighed the noise?

  3. BurntSushi commented on Feb 17, 2020

    @BurntSushi
    Owner

    That PR was from 6 years ago. I don't have any context on it now. FWIW, I've only ever run into this problem with quickcheck specifically. I do not think it is endemic to "heavily functional" code.

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions