【问题标题】:Why does Rust not permit type inference for local constants?为什么 Rust 不允许对局部常量进行类型推断?
【发布时间】:2017-01-28 12:28:14
【问题描述】:

我理解为什么不允许对模块级常量进行类型推断(与不允许对函数进行类型推断的原因相同)。但是,为什么 Rust 不允许对 local 常量进行类型推断?

fn main() {
    const N = 1; // error: expected `:`, found `=`
    let n = 1;   // OK
}

还有比一致性更深刻的原因吗?

【问题讨论】:

    标签: rust


    【解决方案1】:

    据我所知,函数内部的 const 和函数外部的 const 没有区别。它们都是同一个东西,所以它们遵循相同的规则。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-29
      • 2020-08-29
      • 1970-01-01
      • 2016-07-12
      • 1970-01-01
      相关资源
      最近更新 更多