When a function is only called from tests rust complains that it is never used. Why does this happen and how to fix this?
Example:
fn greet() {
println!("Hello!")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_greet() {
greet();
}
}
I get the following compiler warning:
Compiling playground v0.0.1 (/playground)
warning: function is never used: `greet`
--> src/lib.rs:1:4
|
1 | fn greet() {
| ^^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: 1 warning emitted