docs

#E0013: 區塊開頭的結構字面值

在 if、while、match 或 for 的開頭部分,{ 會開啟主體,所以放在那裡的結構字面值會被錯誤解讀。請用括號把字面值包起來:if p == (Point { x: 0, y: 0 }) { .. }。

nabi
struct P { x: i32; }

match P { x: 2 } {
    P { x } => println(f"{x}"),
}
error[E0013]: a struct literal can't start a block's head: its `{` would open the body
  --> main.nabi:3:7
   |
 3 | match P { x: 2 } {
   |       ^^^^^^^^^^
   |
   = help: wrap the struct literal in parentheses: `(P { x: 2 })`

用括號把字面值包起來:

nabi
struct P { x: i32; }

match (P { x: 2 }) {
    P { x } => println(f"{x}"),
}
2

相關錯誤碼:E0010 非預期的語彙單元

發現錯誤? 在 GitHub 上編輯此頁 最後更新: