我有一个功能,其缩写版本可能如下:
loop {
let mut changed = false;
for p in 0..sys.len() {
k = ...
if k == None { continue; }
// some stuff
for (v, _) in &key.0 {
// some stuff
loop {
if n == 2 {
changed = true;
} else if n % 2 == 0 {
changed = true;
} else if n >= 2 {
changed = true;
} else {
changed = true;
}
}
}
}
if !changed { return; }
}
您可以看到在最后一个if语句中访问该标志。但是我收到了这条警告信息:
warning: value assigned to `changed` is never read
202 | changed = true;
| ^^^^^^^
|
= note: #[warn(unused_assignments)] on by default
我没有收到任何其他警告/错误消息。这是为什么?
答案 0 :(得分:10)
因为你永远不会退出内循环吗?