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

Unable to silence lints #217

Open
jhpratt opened this issue Sep 23, 2023 · 1 comment
Open

Unable to silence lints #217

jhpratt opened this issue Sep 23, 2023 · 1 comment

Comments

@jhpratt
Copy link

jhpratt commented Sep 23, 2023

#[rstest]
#[case("[optional ", "expected opening bracket at byte index 9")]
fn error_display_owned(#[case] format_description: &'static str, #[case] error: &'static str) {
    assert_eq!(
        format_description::parse_owned::<2>(format_description)
            .unwrap_err()
            .to_string(),
        error
    );
}

This correctly triggers clippy::unwrap_used. However, placing #[allow(clippy::unwrap_used)] on the function does not silence the lint. This is the case regardless of the position of the attribute.

Here is the current expansion (without an #[allow] attribute).

// `#[allow]` needs to be present here.
#[cfg(test)]
fn error_display_owned(format_description: &'static str, error: &'static str) {
    {
        assert_eq!(
            format_description::parse_owned::<2>(format_description)
                .unwrap_err()
                .to_string(),
            error
        );
    }
}
#[cfg(test)]
mod error_display_owned {
    use super::*;
    #[test]
    fn case_1() {
        let format_description = {
            use rstest::magic_conversion::*;
            (&&&Magic::<&'static str>(std::marker::PhantomData)).magic_conversion("[optional ")
        };
        let error = {
            use rstest::magic_conversion::*;
            (&&&Magic::<&'static str>(std::marker::PhantomData))
                .magic_conversion("expected opening bracket at byte index 9")
        };
        error_display_owned(format_description, error)
    }
}

Perhaps #[allow], #[warn], #[deny], and #[forbid] should be special-cased such that they are copied onto the resulting function? I have no idea how feasible this is.

@la10736
Copy link
Owner

la10736 commented Sep 25, 2023

I should think about that. I guessed that the attributes before the function should act as test's attributes but maybe I was wrong. Maybe only a small subset like should_panic, ignore and skip are test's attributes.

I'm little scared because when the user use the injected tests attribute I cannot know what attributes this test attribute will handle... I can handle all standard attributes as tests attributes and move the others to the function but I should also introduce a syntax that the user can use to force some attribute to be applied to the test instead the function.

I'll com back here to draft the new syntax.

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