E4046#
一个公开的定义不能依赖私有实体。
错误示例:#
priv trait I {
m(Self) -> Unit
}
pub impl I for Int with m(self) {
ignore(self)
}
在上述例子中,试图为类型 Int 实现一个私有特征 I,但实现本身是公开的,这是不允许的。在第 2 行报错:
A public definition cannot depend on private trait
建议#
调整特征或实现的可见性以互相匹配:
pub(open) trait I {
m(Self) -> Unit
}
pub impl I for Int with m(self) {
ignore(self)
}
pub fn call_i(x : Int) -> Unit {
I::m(x)
}