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

#[fixture]: Weird behaviour with where #116

Closed
aliemjay opened this issue Apr 24, 2021 · 7 comments
Closed

#[fixture]: Weird behaviour with where #116

aliemjay opened this issue Apr 24, 2021 · 7 comments

Comments

@aliemjay
Copy link

Using #[fixture] with where syntax yields some errors with unclear error messages.
Here is my test code:

// rustc 1.51.0
// rstest 0.7.0

use rstest::{fixture, rstest};  

#[fixture]
fn args() -> Vec<i32> {Default::default()}

#[fixture]
fn func<T, S>(args: T)
where
    T: IntoIterator<Item = S>, /* error[E0412]: cannot find type 'S' in this scope */
    S: Copy,
{
}

#[fixture]
fn func2<T>(args: T)
where
    T: IntoIterator,
    T::Item: Copy,  /* error[E0433]: failed to resolve: use of undeclared type 'T' */
{
}

/* However, an equivalent single-line 'where' specs works fine */
#[fixture]
fn func3<S>(args: impl IntoIterator<Item = S>)
where
    S: Copy,
{
}

/* #[rstest] works fine */
#[rstest]
fn func<T, S>(args: T)
where
    T: IntoIterator<Item = S>,
    S: Copy,
{
}
@la10736
Copy link
Owner

la10736 commented Apr 24, 2021

Ok, thanks to report it: you catch a wired case.

I need to clean where clause to remove unused types for partial arguments implementations. I should take in account when a type is mentioned just in type constrains and not explicit in function arguments. In this case S is implicit in T and cannot be removed.

Ok I'll add this case to may test and try to fix it.

@aliemjay
Copy link
Author

Great! and thanks again for this great crate!

@la10736
Copy link
Owner

la10736 commented Apr 25, 2021

Unfortunately I cannot fix it for the next release (I'm releasing right now) because the fix need some develop effort and I should just release an hot fix and a new feature ... I hope to fix it ASAP in the next weeks.

@la10736
Copy link
Owner

la10736 commented May 8, 2021

Ok, there are two issues here in the code that clean the signature (we should do it to create the partials impls). We perform clean action also in the base impl and that exposed the issue in some simpler cases.

  1. S will be discarded because we cannot recognize the transitive dependencies: we don't use S directly in the argument list or in the return type but S is part of T that is used as input argument type.
  2. when we implement func2() default impl the code don't remove the T::Item: Copy where clause because T != T::Item

@la10736
Copy link
Owner

la10736 commented May 8, 2021

Ok I'va also noted that we miss follow:

  • const generics
  • lifetime attribute

I've no idea if a lifetime attribute can be useful for fixture... but I'll implement it

la10736 added a commit that referenced this issue May 8, 2021
@la10736 la10736 closed this as completed in f2ab8bb May 9, 2021
la10736 added a commit that referenced this issue May 9, 2021
@la10736
Copy link
Owner

la10736 commented May 16, 2021

Fixed in 0.10.0 Released today

@aliemjay
Copy link
Author

Thanks you for your time! Very much appreciate it.

I've tried to understand the code, now my brain hurts :)

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

No branches or pull requests

2 participants