Skip to content

unnecessary_cfg_test #8697

Open
Open
@yoav-lavi

Description

@yoav-lavi

What it does

Since #[test] is already implicitly #[cfg(test)], it would not be needed to use #[cfg(test)] directly on a function.

I propose this lint to catch cases of

#[cfg(test)]
#[test]
fn test() {}

Suggesting instead to either remove the cfg (for inline tests), to add it to the module itself (for inline modules, e.g. #[cfg(test)] mod test {}) or to use #![cfg(test)] at the head of the file (for test files).

Lint Name

unnecessary_cfg_test

Category

style

Advantage

Removes redundant code

Drawbacks

None that I'm aware of

Example

#[cfg(test)]
#[test]
fn test() {}

Could be written as:

// test file
#![cfg(test)]

#[test]
fn test() {}

// inline test
#[test]
fn test() {}

// inline test module
#[cfg(test)] 
mod test {
    #[test]
    fn test() {}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsS-blockedStatus: marked as blocked ❌ on something else such as an RFC or other implementation workT-macrosType: Issues with macros and macro expansion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions