E4010

E4010#

pub is not allowed on default implementation for traits. The default implementation has the same visibility as the trait itself.

错误示例:#

pub(open) trait Stringer {
  stringify(Self) -> String = _
}

pub impl Stringer with stringify(_self) { "hey" }

在上面的示例中,pub 关键字用于 Stringer 特性的默认实现,这是不允许的。

建议#

移除 pub 关键字,使默认实现与特性本身具有相同的可见性:

pub(open) trait Stringer {
  stringify(Self) -> String = _
}

impl Stringer with stringify(_self) { "hey" }