la10736 / rstest

Fixture-based test framework for Rust
Apache License 2.0
1.21k stars 43 forks source link

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

Closed sadderchris closed 5 months ago

sadderchris commented 9 months ago

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 commented 9 months ago

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