小编Als*_*afi的帖子

从 if 语句内部返回时键入不匹配

以下代码无法编译:

fn testing() -> i32 {
    let x = 5;
    if x == 5 {
        5
    }
    6
}
Run Code Online (Sandbox Code Playgroud)

出现此错误:

fn testing() -> i32 {
    let x = 5;
    if x == 5 {
        5
    }
    6
}
Run Code Online (Sandbox Code Playgroud)

如果我return在 前面放了一个显式5,或者如果我把6里面放了一个else块,一切正常。Rust 到底在抱怨什么?

type-mismatch rust

4
推荐指数
1
解决办法
365
查看次数

标签 统计

rust ×1

type-mismatch ×1