docs

你正在阅读 v0.1.2 的文档。Nabi 0.1.2 已不再提供支持。 最新版本:v0.1.3 →

本页尚未翻译,以下为英文原文。

#E0038: variable named like a nested function

A variable and a nested function in the same block share a name. A nested function is visible in the whole block, so the name would mean both: rename one of them.

nabi
fn main() {
    fn step(x: i32) -> i32 { x + 1 }
    let step = 2;
    println(f"{step}");
}
error[E0038]: `step` names both a variable and a nested function in this block
  --> main.nabi:3:5
   |
 3 |     let step = 2;
   |     ^^^
   |
   = help: a nested function is seen in its whole block, so rename one of them: `let step2 = ..` or `fn step2(..)`

Give the variable or the function its own name:

nabi
fn main() {
    fn step(x: i32) -> i32 { x + 1 }
    let steps = 2;
    println(f"{step(steps)}");
}
3

A second let of a variable's name is fine: it makes a new variable (5.1.4).

Related: E0026 name defined more than once

Found a mistake? Edit this page on GitHub. Last updated