Add IntoIterator
impl for arrays by value (for [T; N]
) by LukasKalbertodt · Pull Request #65819 · rust-lang/rust (original) (raw)
And I thought I ran every test locally... Anyway, we now have an example of code that would break due to this change:
let test_vector = [ |
---|
(TestType::UnitTest, unit.warn.as_millis() - 1, false, false), |
(TestType::UnitTest, unit.warn.as_millis(), true, false), |
(TestType::UnitTest, unit.critical.as_millis(), true, true), |
(TestType::IntegrationTest, integration.warn.as_millis() - 1, false, false), |
(TestType::IntegrationTest, integration.warn.as_millis(), true, false), |
(TestType::IntegrationTest, integration.critical.as_millis(), true, true), |
(TestType::DocTest, doc.warn.as_millis() - 1, false, false), |
(TestType::DocTest, doc.warn.as_millis(), true, false), |
(TestType::DocTest, doc.critical.as_millis(), true, true), |
]; |
for (test_type, time, expected_warn, expected_critical) in test_vector.into_iter() { |
let test_desc = typed_test_desc(*test_type); |
let exec_time = test_exec_time(*time as u64); |
assert_eq!(options.is_warn(&test_desc, &exec_time), *expected_warn); |
assert_eq!(options.is_critical(&test_desc, &exec_time), *expected_critical); |
} |
This piece of code is interesting because we can guess how this code came to be: the variable is called test_vector
, so it likely started out as Vec
. But at some point the author changed it to a simple array (or they just forgot the vec!
). Then some errors were printed by the compiler, which were fixed by adding a bunch of *
dereference operations. But the author didn't notice the wrong/strange into_iter()
.
Now we have to see how often this exists in the real world.