E0045

E0045#

所有方法都有默认实现的特征必须用 impl Trait for Type 显式实现。

最初,如果一个特征的每个方法都有默认实现,MoonBit 允许 任何 类型隐式地实现这个特征,无需显式地写 impl。这一行为目前一倍废弃,用户应该通过 impl Trait for Type 语法显式实现这些特征。声明来实现特征。目前,这一废弃处于迁移阶段,MoonBit 依然支持旧的语义,但如果程序使用了普通方法来隐式地实现特征,编译器就会产生该警告。

错误示例#

pub(open) trait Foo {
  foo(Self) -> Unit = _
}

impl Foo with foo(_)  {
}

test {
  let x : Int = 0
  Foo::foo(x)
}

建议#

为想要实现对应特征的类型添加显式的 impl 声明。

impl Foo for Int