Open
Description
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() {}
}