Why does this code give me strange results?
const VAR1: u16 = 1;
const VAR2: u16 = 2;
const VAR3: u16 = 3;
const VAR4: u16 = 4;
#[cfg(test)]
mod tests {
// use {VAR1, VAR2, VAR3, VAR4};
#[test]
fn test_match() {
let a = 4;
match a {
VAR1 => {
println!("matched: 1");
}
VAR2 => {
println!("matched: 2");
}
VAR3 => {
println!("matched: 3");
}
VAR4 => {
println!("matched: 4");
}
_ => {
println!("not matched");
}
}
}
}
When the line // use {VAR1, VAR2, VAR3, VAR4};
is commented, then the result of test execution is matched: 1
. When use {VAR1, VAR2, VAR3, VAR4};
is not commented, then the result is correct and is matched: 4
.
Why the compiler doesn't fail in the first case ?
cargo test -- --nocapture
rustc --version
rustc 1.16.0-nightly (7e38a89a7 2017-01-06)
You can find the test project code here https://github.com/asmsoft/rust-match-test