提交 86b10671 编写于 作者: W Without Boats

Associated consts are not object safe.

上级 15ce5409
......@@ -37,6 +37,9 @@ pub enum ObjectSafetyViolation {
/// Method has something illegal
Method(ast::Name, MethodViolationCode),
/// Associated const
AssociatedConst(ast::Name),
}
impl ObjectSafetyViolation {
......@@ -54,6 +57,8 @@ pub fn error_msg(&self) -> Cow<'static, str> {
in its arguments or return type", name).into(),
ObjectSafetyViolation::Method(name, MethodViolationCode::Generic) =>
format!("method `{}` has generic type parameters", name).into(),
ObjectSafetyViolation::AssociatedConst(name) =>
format!("the trait cannot contain associated consts, such as `{}`", name),
}
}
}
......@@ -141,6 +146,10 @@ fn object_safety_violations_for_trait(self, trait_def_id: DefId)
violations.push(ObjectSafetyViolation::SupertraitSelf);
}
violations.extend(self.associated_items(trait_def_id)
.filter(|item| item.kind == ty::AssociatedKind::Const)
.map(|item| ObjectSafetyViolation::AssociatedConst(item.name)));
debug!("object_safety_violations_for_trait(trait_def_id={:?}) = {:?}",
trait_def_id,
violations);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册