cargo build succeed for the following code:
#[cfg(test)]
mod tests {
#[test]
fn func() {
let x = 1;
sss
}
}
cargo build fail for the following code:
#[cfg(test)]
mod tests {
#[test]
fn func() {
sss
let x = 1;
}
}
The #[cfg(test)] annotation on the tests module tells Rust to compile and run the test code only when you run cargo test, not when you run cargo build.
So why rustc still compiles mod tests that is annotated with #[cfg(test)] ?