#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 上编辑此页 最后更新: