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

Misleading error messaging when defining a test that includes a lifetime argument #230

Open
sadderchris opened this issue Feb 15, 2024 · 1 comment

Comments

@sadderchris
Copy link

sadderchris commented Feb 15, 2024

Consider the following example:

#[rstest]
#[case("foo", |_| {})]
fn test<'a>(#[case] text: &'a str, #[case] body: fn(t: &'a str)) {
    body(text)
}

This results in the following error:

error[E0261]: use of undeclared lifetime name `'a`
   --> src/lib.rs:12:34
    |
34  |     fn foo<'a>(#[case] text: &'a str, #[case] body: fn(text: &'a str)) {
    |           -                   ^^ undeclared lifetime
    |           |
    |           help: consider introducing lifetime `'a` here: `<'a>`

For more information about this error, try `rustc --explain E0261`.

Rust handles this just fine, so this seems like an issue with rstest.

It feels like this should be possible. Of course, you can work around this by using the 'static lifetime here instead of an arbitrary 'a. However, it would be nice to at least provide some better error messaging here if possible or document this as a shortcoming somewhere, as the current error is really misleading.

@la10736
Copy link
Owner

la10736 commented Feb 16, 2024

Yes... It's an issue. Thx for reporting it!

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