mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-22 18:15:07 +03:00
Associated consts are not object safe.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user