E0052

E0052#

A loop variable is not updated in loop.

当循环变量未更新时,这可能是一个潜在的错误,您忘记更新它,从而导致无限循环。

错误示例#

///|
pub fn f() -> Unit {
  for i = 0, radix = 10; i < 10; {
    println(i.to_string(radix~))
  }
}

建议#

有几种方式可以修复这个警告:

  • If this variable is indeed constant during the loop, you can remove it from the initialization and make it constant

  • 如果您的代码依赖于变量的变化,您应该在循环中的某个地方更新它。

///|
pub fn f() -> Unit {
  let radix = 10
  for i = 0; i < 10; i = i + 1 {
    println(i.to_string(radix~))
  }
}